Subj : Re: thread control by mutex, predicates and conditions puzzle To : comp.programming.threads From : David Schwartz Date : Fri Jan 07 2005 07:35 pm "roland" wrote in message news:LwBDd.40033$BO5.38686@news.chello.at... > Jomu wrote: >> What is this stop/start action thing? Do you want to freeze your >> threads only at some points or wherever they happen to be when you stop >> them? > Say, your thread is blocking on IO. Why not just avoid blocking on I/O? > Now an external thread that is in > charge of master control needs to tell: quit and restart IO. > But I do not want to cancel the entire thread! (Imagine I have other > valuable > state information in my thrad.) How you do this depends upon the rest of your architecture, but basically you just remove the I/O from the list of I/Os that your I/O-doing threads use to decide what I/O to do. > How should I go for it when I > 1) want a single thread wide master control while still be able to > wait on different things during the threads lifetime > 2) _and_ write code with portability in mind? (The IO clearly is > highly system dependant.) > > I would be very glad if you could point me to such a pattern, since > I am too a bit concerned of the "thundering herd" problem my broadcast > could cause. Use non-blocking I/O. The threads that do I/O keep state on what I/Os they're working on, and other threads can access that state information with suitable locks. You're setting things up to be much harder than they have to be. DS .