Hacker News new | past | comments | ask | show | jobs | submit login
The Story of Microsleep (2012) (scalibq.wordpress.com)
35 points by boovic on June 1, 2023 | hide | past | favorite | 12 comments



I thought this was going to be about polyphasic sleeping.


Same. To anyone who hasn’t gone down the polyphasic sleep rabbit hole, it’s quite the trip.


Is that still a thing people do? I thought Lindsay Lohan dragged Steve Pavlina back to the 8th circle of hell when she tattooed his cult symbol on her arm.


If you, like me, were interested in learning more about the physiological phenomenon, perhaps wikipedia will slake your thirst: https://en.wikipedia.org/wiki/Microsleep


I had this happen to me once while driving. One moment, I was totally alert - the next, I was feet away from my car being impaled by the side rail of the highway.

What was so disconcerting is that while I had been operating on less sleep than I should have, I didn’t feel drowsy or tired before this happened. Thankfully I didn’t crash and was able to get a nap and continue my trip.


Spin-wait seem a wasteful solution. It seems to me that some sort of pseudo-cooperative scheduling implemented via some event or semaphore and keeping track of the current used 'quantum' would be better.


Please correct me if I am wrong , Linux has HRTs introduced just to solve this problem right ? Windows doesnt have anything like that ?

How is micro-sleep solving the problem that OP has underlined ? >The resulting behaviour appears to be that the message queues are filling up, and as a result, not only the windows themselves are becoming unresponsive, but the system as a whole is starting to respond poorly. This seems to happen even on a quadcore system with HyperThreading, which should be able to handle 8 threads simultaneously. So just having enough cores is not always the answer, apparently.


Yes, I posted a followup which investigates the issue somewhat further. It appears to be some bug with the message queue handling, specifically when the UI is in Aero mode. In classic mode, the problem is not there. In Windows XP, the problem is also not there. https://scalibq.wordpress.com/2012/03/28/the-story-of-micros...


You're right. But sometimes, you can't afford the cost of the context switch.


but the proposed solution is literally trying to context switch in a loop


Exactly. As I tried to explain, you NEED a context switch (which doesn't make it a spin-wait) in order to avoid the deadlock between your main loop and the processing of the Windows message queue (and as you see, I do check the quantum, via QueryPerformanceCounter()). The goal was to find a way that didn't deadlock the system, while also not wasting so much time that it impacts your framerate to the point where you can't even drive a high-refresh display at say 144 Hz.

Ofcourse I'm open to even better solutions, but so far this is the best solution I know of.

I doubt that events/semaphores would work better, as they'd be implemented as spinlocks for short periods of time, in which case they wouldn't actually trigger a context switch. Once you use a long enough time to get to a context switch, it's probably going to be worse than doing the context switch explicitly, the way I do here.

All in all, it's a bug in Windows Aero, as the followup blog expained (not sure if it was ever fixed in later versions of Windows, I haven't been working with multiple display adapters/screens in situations like these in recent years): https://scalibq.wordpress.com/2012/03/28/the-story-of-micros...


I remember those times in high school, head would dip sitting at desk, then suddenly jerk awake kicking chair in front of me.

Later in college sleep paralysis man those were brutal.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: