This is the mail archive of the pthreads-win32@sourceware.org mailing list for the pthreas-win32 project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Problem with pthread_cond_timedwait()


Hello,

There is a strange problem with pthread_cond_timedwait() in my program
using pthread-win32, I found it doesn't
wait at all. Here is part of the codes,

    struct timespec timeout;
    timeout.tv_sec = time(NULL) + 10;
    timeout.tv_nsec = 0;

    pthread_cond_timedwait( & myCondVar, & mutex->myMutex, &timeout );

This part works as expected under linux. The compiler I used is gcc3.4.2,
and I used the pre-built pthread-win32, v2.7.
Am I using pthread_cond_timedwait() properly?

Another question, I saw in pthread documentations that the "timeout" is
prepare in the following way,

struct timeval now;
struct timespec timeout;

gettimeofday(&now);
timeout.tv_sec = now.tv_sec + 5;
timeout.tv_nsec = now.tv_usec * 1000;

But I found it won't work without modification, in Linux, it complain
gettimeofday() needs another parameter
(something like timezone, if I remember well), and in Windows the compiler
complain gettimeofday() is not
defined. So what is the "most" standard or correct way to prepare "timeout"?

Thanks a lot,

Limin

PS, I was trying to send this email by my gmail account,
but it didn't work with this mailling list.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]