Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> use nonblocking io and an event polling mechanism

Not incompatible with what I said.

> with a timeout to keep an eye on an exit flag

This is the stupid part. You will burn CPU cycles waking up spuriously for timeouts with no work to do. Setting the flag won't wake up the event loop until the timeout hits, adding pointless delay.

You want to make signalling an exit to actually wake up your event loop. Then you also don't need a timeout.

I.e. you should make your "ask to exit" code use the same wakeup mechanism as the work queue, which is what I said at the beginning. Not burning CPU polling a volatile bool in memory on the side.



> This is the stupid part. You will burn CPU cycles waking up spuriously for timeouts with no work to do. Setting the flag won't wake up the event loop until the timeout hits, adding pointless delay.

it's the smart part. waking up at 50hz or 100hz is essentially free and if there's an os bug or other race that causes the one time "wake up to exit" event to get lost, the system will still be able to shut down cleanly with largely imperceptible delay. it also means that it can be ported to systems that don't support combined condition variable/fd semantics.


> You want to make signalling an exit to actually wake up your event loop.

This is exactly what condwait + condsignal do.




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

Search: