Subj : Re: get num waiters on cv To : comp.programming.threads From : Maciej Sobczak Date : Tue May 03 2005 10:51 am David Schwartz wrote: > If you call it from the only thread that signals the condition variable > and you don't use timed waits, then you know that at least that many threads > are waiting. For example, it might make sense to have the thread do the work > itself if the value is zero rather than signalling the condition variable > and then doing something else. If the value is zero, then at least zero threads are waiting (if all these assumptions are met). It might be any positive number before the program even gets to check that value in some conditional statement, because there is no way to prevent other threads to "accumulate" on the synchronization object in the meantime. Any decision that is taken based on this value can already be a wrong decision. This value might be of some use if all other threads are already "frozen" on some synchronization objects (for example during deadlock), but I do not know what the program could do with it. Of course, there is still the case of reading the value without taking any decisions based on it, just like monitoring and displaying the number of active processes or the amount of free memory. This might make sense. But then - if the user is allowed to read the number of threads that are waiting on a synchronization object, then the access to that value should be synchronized as well... :-) -- Maciej Sobczak : http://www.msobczak.com/ Programming : http://www.msobczak.com/prog/ .