From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Bossom, John" To: "'Mikael.Ambrus@elema.siemens.se'" , pthreads-win32@sourceware.cygnus.com Subject: RE: pthread_cond_timedwait Date: Thu, 09 Sep 1999 10:51:00 -0000 Message-id: <450FB96A8F51D31186CD00805F95C7DC036C8F@SOTTEXCH62A> X-SW-Source: 1999/msg00084.html I just saw a potential bug in your code, below: assert( pthread_mutex_lock(&(rdwrp->mutex)) == 0 ); I recommend that you do not call functions within an 'assert' unless you don't mind the compiler optimizing out the 'assert' statement! (i.e. your lock will not happen) Quote from MS Dev Studio, 5.0 for 'assert': "The ANSI assert macro is typically used to identify logic errors during program development, by implementing the expression argument to evaluate to false only when the program is operating incorrectly. After debugging is complete, assertion checking can be turned off without modifying the source file by defining the identifier NDEBUG. NDEBUG can be defined with a /D command-line option or with a #define directive. If NDEBUG is defined with #define, the directive must appear before ASSERT.H is included." I recommend you using: int lockResult; lockResult = pthread_mutex_lock(&(rdwrp->mutex)); assert( lockResult == 0 ); -----Original Message----- From: Mikael.Ambrus@elema.siemens.se [ mailto:Mikael.Ambrus@elema.siemens.se ] Sent: Thursday, September 09, 1999 11:47 AM To: pthreads-win32@sourceware.cygnus.com Subject: pthread_cond_timedwait [Ambrus Mikael] Dear pthreads colleagues, I'm writing a program that uses pthread_cond_timedwait. In the book that I'm using (Pthreads Programming by Nicols, Buttlar & Proulux Farell ) it says that this function should suspend the thread until some other thread calls pthread_cond_signal, pthread_cond_broadcast OR the system timer is greater than or equal to the third argument (abstime). Since clock_gettime is not implemented and I cant find some other function that tells me the system time, I've tried to implement my own version of clock_gettime by using the ansi function clock(). This function returns the number of ticks that has elapsed since the program was started. But it seams that this is not the same absolute time that pthread_cond_timedwait requires since the thread won't awaken. Is there another way to acquire the relevant system time? Another thing that has bothered me is that I recently downloaded the latest snip of phtreads and now my read/write locks won't work. Since the precompiled lib isn't recognised by the linker (neither with gcc v20.1 nor MSVC 6.0) for some reason, I built the libs using the buildlib.bat provided. Here's a snip of the code that fails: int pthread_rdwr_wunlock_np ( pthread_rdwr_t *rdwrp ){ assert( pthread_mutex_lock(&(rdwrp->mutex)) == 0 ); if (rdwrp->writers_writing == 0) { assert( pthread_mutex_unlock(&(rdwrp->mutex)) == 0 ); return(-1); }else{ rdwrp->writers_writing = 0; assert(pthread_cond_broadcast(&(rdwrp->lock_free)) == 0); }; assert( pthread_mutex_unlock(&(rdwrp->mutex)) == 0 ); return(0); }; pthread_cond_broadcast returns EINVAL. Does anyone recognise this problem? Wkr Michael Ambrus Siemens Elema >