Subj : Re: How to manage time-slicing in Pthreads programs? To : comp.programming.threads From : Marcin 'Qrczak' Kowalczyk Date : Sun Feb 20 2005 05:27 pm "Joe Seigh" writes: >> How? >> >> The program wants some action to be executed when the user presses ^C >> or when a timer expires. How the action would be executed? In a newly >> created thread? What would it use to notify the main thread that it >> should abort what it is currently doing in some convenient place? [...] > Most GUI's use event queues. Which require checking them in regular intervals. Most Unix programs don't have a GUI. I'm glad that they can be promptly interupted without the programmer having to remember to spread checks for an event queue over the program. > Most of the synchonization api on windows, unix, and java has > timeout options. Timeout on a waiting function doesn't help with interrupting an active computation. I want the computation to proceed as fast as possible, but to stop in a safe point after some time elapses. Checks at safe points are inserted automatically by my compiler. Something has to be inserted anyway to resize the stack when it overflows. Comparing two volatile variables is about as fast as it can portably be done - I would not like to have to check a mutex or an event queue in addition to that. -- __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/ .