Hacker News new | ask | show | jobs
by deith 2360 days ago
Are userland spinlocks the reason most games use 100% of one or several cores even when they are minimised and doing nothing?
1 comments

Kinda. Normal Windows applications use a system call to wait for new messages to arrive, and then react to those. This is very similar to waiting for a mutex, and it allows the kernel to put the thread to sleep until a message comes along.

Games often integrates the message loop into their game loop. In their loop, they poll to see if any new message has arrived, and if so handles it. In any case it does it's game thing.

If there's not much to do, because the game is paused when it's minimized for example, this spins much like a spinlock spins. If, in addition, it has some other threads it's synchronizing using spinlocks then yes, it can cause it to burn several cores worth doing nothing.

Better games handles the loop differently while the game is minimized, for example doing the default wait-for-message variant.