Hello jean, first at all thank you for your help. Look at page 81 in the book PTHREADS programming. There is a sample, how to deal with pthread condition varaibles. The previosly described problem encounteres on a single processor system with WINNT 4.0 also in this example. Try this out fist without Sleep(0) line in inc_count function then uncomment Sleep(0) and try it again you will see what happens. What you can also try is to create first the watch_count thread, to let him enter in to the while, so that pthread_cond_wait function unlocks the count_mutex while waiting. Then start inc_count with and whithout Sleep(0). #include #include "pthread.h" #define TCOUNT 10 #define WATCH_COUNT 12 int count=0 ; pthread_mutex_t count_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t count_treshold_cv = PTHREAD_COND_INITIALIZER; int thread_ids[3] = {0,1,2}; void* watch_count(int *idp) { pthread_mutex_lock(&count_mutex) ; while( count<=WATCH_COUNT){ pthread_cond_wait(&count_treshold_cv, &count_mutex); printf( "watch_count(): Thread %d, count is %d\n", *idp, count); } pthread_mutex_unlock(&count_mutex) ; return NULL ; } void* inc_count(int *idp) { int i; for(i=0;i > Hello, > > Inside your thread, it sould waiting for a specfic signal and make > broadcast the signal for every thread that running. > > For ex: inside all thread except the nain thread: > > for ever { > > wait until specific signal > } > > in the main thread : > post a message in queue thread. > wake up thread by BROADCASITING message for all thread. > > -------------------------------------------------------------------- > EX : C++ code. > Si Main thread and all other thread sshould wait on the same condion > variable and mutex. > A good sample how to deal with queue and threads can be found in the > book : > PTHREADS programming of O'Reilly, Nichols, Buttlar & Farell. ISBN- > 1-56592-115-1 > Buy it, very good investisment ! > Hope, this help you. > > Waiting thread: > ------------- > macro : SNS_COND_WAIT = pthread_cond_wait > macro : SNS_COND_BROADCAST = pthread_cond_broadcast > > LONG BaseQueue::Q_WaitForEvent( VOID ) { > > while ( (m_lQueueSize == 0) && (!m_bQueueShutdown) ) { > > if ( SNS_COND_WAIT(&m_condQueueNotEmpty, &m_mutexQueueLock ) != 0 ) > > return Q_LogError( m_szQName, SNSLOG_ERROR, SNS_E_SYS_COND_WAIT, > "Q_WaitForEvent" ); > } > > return NO_ERROR; > } > > Main thread: > ----------- > > if ( SNS_COND_BROADCAST(&m_condQueueNotEmpty) != 0 ) > Q_LogError( m_szQName, SNSLOG_ERROR, SNS_E_SYS_COND_BROADCAST, > "Q_AddEvent" ); > > -- > Jean > > Taci Ülker wrote: > > > > Hello all, > > > > I am developing a software based on win32-pthreads (latest available). > > My problem I encountered is: > > > > I have an object for message queuing, wich is intended to let the > > callers thread wait by getMessage(LPSSMSG lpMsg), until a new > > message is posted by any other thread. Now imagine, the thread > > which is waiting for new messages is in status ACTIVE (sleeping or > > not running) in operating system. The thread wich is posting a new > > message is in status RUNNING. This running thread pushes at first > > a new message into the queue and signals the waiting thread to be > > waked up and unlocks the mutex immediately, so that other threads > > can push further new messages. > > > > Now, the problem is when the signal is given to wake up the waiting > > thread by the first message pushing thread then the OS dont switch > > automatically its thread execution. This means if the thread is not > > waked up, because it is not switched to stutus RUNNING and an other > > thread pushes further new message in to the queue and signals also > > the waiting thread then what is about the first and second signals? > > > > I am actually switching thread execution with sleep(0) function, > > after each message posting. > > -- > Jean ANDRE > Tel: (514) 398-9799 #24 Fax: (514) 398-9353