Subj : Re: really simple portable eventcount... To : comp.programming.threads From : Joe Seigh Date : Sun Mar 06 2005 09:19 am On Sat, 5 Mar 2005 22:54:59 -0800, SenderX wrote: Plus, I don't think you need to optimize wait in any case. It's already going to be slow. So the compare of the eventcount outside of the locked region can be removed. It's a pretty small window between the test of the condition and the test of the eventcout. The eventcount is unlikely to have been set in that amount of time so that test doesn't buy you that much. The later test is necessary since you need to test it before potentially blocking. > > > int wait( int cmp ) > { > int local = m_ec & 0x7FFFFFFF; > > if ( local == cmp ) > { > pthread_mutex_lock( &m_mutex ); > > local = m_ec & 0x7FFFFFFF; > > if ( local == cmp ) > { > ++m_waiters; > > pthread_cond_wait( &m_cond, &m_mutex ); > } > > pthread_mutex_unlock( &m_mutex ); > } > } > > }; > -- Joe Seigh .