Subj : Re: Windows Suspend/ResumeThread API equivalent for Linux or POSIX? To : comp.programming.threads From : Oliver S. Date : Thu May 12 2005 01:54 am >> Is there a way I can achieve similar functionality on Linux >> or POSIX based systems? > You can do so any way you like with the cooperation > of the thread you would like to suspend or resume. Of couse you can ... > Without the cooperation of that thread, it simply cannot be done > safely. .... but that's not true ! A particular thread can be stopped any time _by_another_thread_ and with modern operating-systems, threads can even be stopped in kernel-mode when they didn't stop the schedu- ler; this is usually done when a spinlock is acquired. > There would be essentially nothing you could do between the > suspend and the resume. When the thread wants to stop itself, of course there wouldn't be any chance to wake up itself (except when it stops itself for an interval by calling Sleep()/sleep()). > Usually when people ask this question, they are barking up the > wrong tree. Why do you think you need to suspend a thread? Imagine you have an application which performes a computation-time -intensely task in the background with a worker-thread (f.e. a rende- ring-application). And this app would provide a pause-button to sus- pend this calculations to free computing-power for a while. Without an API similar to SuspendThread / ResumeThread you would have to poll a volatile flag which is shared between the worker-threads and the supervising thread. That takes performance (esspecially when mul- tiple worker-threads share this flag on a SMP-system and need to MESI -broadcast for a newer version of the cache-line containing that flag to all CPUs) and when you need a fine granularity of the poll-inter- val, you're likely to insert that polling-code in a lot of functions which aren't related to this threading-issue. Don't you think an API like SuspendThread / ResumeThread is much smarter in that case ? And as suspending an resuming a thread can be considered as a longer in- terval of suspension through preemption, such an API could be provi- ded by an operating-system without a significant cost in code-size or growth in complexity of the OS. .