Problem with pthread_cond_timedwait()
Dmitrii Sernii
bogolt@gmail.com
Tue Sep 27 13:16:00 GMT 2005
Hello,
The problem here is that pthread_cond_timedwait takes absolute time,
but you passed relative timeout.
to make pthread_cond_timedwait waike up after you called it, you need
to get current time, and then add timeout you need.
In the sampe you provide your pthread_cond_timedwait waikes up before
it actually starts.
Under win32 you can use GetLocalTime to retieve current time.
Tuesday, September 27, 2005, 2:12:58 PM, you wrote:
FL> Hello,
FL> There is a strange problem with pthread_cond_timedwait() in my program
FL> using pthread-win32, I found it doesn't
FL> wait at all. Here is part of the codes,
FL> struct timespec timeout;
FL> timeout.tv_sec = time(NULL) + 10;
FL> timeout.tv_nsec = 0;
FL> pthread_cond_timedwait( & myCondVar, & mutex->myMutex, &timeout );
FL> This part works as expected under linux. The compiler I used is gcc3.4.2,
FL> and I used the pre-built pthread-win32, v2.7.
FL> Am I using pthread_cond_timedwait() properly?
FL> Another question, I saw in pthread documentations that the "timeout" is
FL> prepare in the following way,
FL> struct timeval now;
FL> struct timespec timeout;
FL> gettimeofday(&now);
FL> timeout.tv_sec = now.tv_sec + 5;
FL> timeout.tv_nsec = now.tv_usec * 1000;
FL> But I found it won't work without modification, in Linux, it complain
FL> gettimeofday() needs another parameter
FL> (something like timezone, if I remember well), and in Windows the compiler
FL> complain gettimeofday() is not
FL> defined. So what is the "most" standard or correct way to prepare "timeout"?
FL> Thanks a lot,
FL> Limin
FL> PS, I was trying to send this email by my gmail account,
FL> but it didn't work with this mailling list.
--
Best regards,
Dmitrii Sernii
More information about the Pthreads-win32
mailing list