2 ms·
How do you handle long lasting operations like checking something from time to time? Seems to me this is a natural use for a thread.
by maxxxxx 9y ago
How do you handle long lasting operations like checking something from time to time? Seems to me this is a natural use for a thread.
- winstonewert 9y agoSchedule a timer, and respond to the timer events. Its a waste of resources to have a thread hanging around sleeping all the time.
- jdmichal 9y agoThis is basically "There is no Thread": https://blog.stephencleary.com/2013/11/there-is-no-thread.html https://blog.stephencleary.com/2013/11/there-is-no-thread.ht... There are times when you can offload an asynchronous task to non-CPU hardware, in which case the blocking thread can disappear. The thread reappears when the hardware asynchronously informs the CPU of task completion. (This idea is what Node.JS is entirely reliant upon.) Consider if we didn't have timing hardware to handle this task for us. We could implement a timer with a spin-loop thread which checks the clock and fires off events.