Boost thread suspend/resume

Hi,all We can create a thread very easily. While, I don’t know how to suspend and then resume it. Does anyone have any idea? Thanks, peace

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tuesday 22 January 2008 22:16 pm, 申和平 wrote:
Hi,all
We can create a thread very easily. While, I don’t know how to suspend and then resume it.
Does anyone have any idea?
Have you looked at boost::condition? - -- Frank -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFHl1H25vihyNWuA4URAjfaAKCmDd4PSuKDYrJJ17/FOXwUvNWiXACfdMXV JRZ7Ez6nDjJNa7npMdHHWC0= =ZuSh -----END PGP SIGNATURE-----

hp.shen@hyaptech.com wrote:
We can create a thread very easily. While, I don't know how to suspend and then resume it.
As far as I'm aware, Boost.Thread doesn't provide any way to asynchronously suspend and resume threads from other threads. Neither does the proposed standard threads library. In POSIX, there are no pthread_* calls to do this. Solaris apparently has/had thr_suspend() and thr_resume(). LinuxThreads may work if you send SIGSTOP and SIGCONT to the thread, but POSIX says that they should affect the whole process and I guess that that is what NPTL (the newer Linux pthreads implementation) does. Does anyone know what Windows has? One possible implementation, for POSIX systems, is to have a condition variable per thread and a signal handler. To suspend a thread, send it the signal; the signal handler waits on the condition. To resume the thread, wake the condition. I think that that could be done on top of the existing Boost.Thread or the proposed std::threads, though maybe some sort of hook is needed so that the signal handler can be set up when a new thread is created. But in general, I suspect that suspend()/resume() is used to implement "do-it-yourself scheduling". Wouldn't it be better to instead let the operating system do the scheduling, and to just change the thread priorities as necessary? i.e. replace thread_suspend() with set_priority(low) and thread_resume() with set_priority(high). Of course, Boost.Threads and std::threads don't have functions for that either. POSIX has functions to do this; presumably they could be used with std::threads using the "native handle" functionality. Can they be used with Boost.Threads? Is there enough commonality between Windows and POSIX to do something cross-platform? Regards, Phil.

On Wednesday 23 January 2008 04:16, 申和平 wrote:
We can create a thread very easily. While, I don’t know how to suspend and then resume it.
Just to elaborate on Frank's response, there is a reason this is not directly supported. The problem with simply suspending a thread somewhere in the middle (i.e. somehow settings its timeslice to zero) is that it might just be in the middle of malloc() with a lock around the heap held. Any other thread would then block on malloc(), possibly forever. Therefore, stop the thread in a controlled state using a condition. Uli
participants (4)
-
Frank Mori Hess
-
Phil Endecott
-
Ulrich Eckhardt
-
申和平