This is the mail archive of the
pthreads-win32@sourceware.org
mailing list for the pthreas-win32 project.
Re: Problem with pthread_cond_timedwait()
Hi Dmitrii,
Thank you very much!
The problem is solved after locking the mutex before calling the function.
I was trying to implement a sleep() function using pthread_cond_timedwait(),
so the thread calling this function will never be signaled. I thought the
using mutex is necessary only if pthread_cond_timedwait() is used together
with pthread_cond_signal/broadcast(). In fact, it works in Linux without
locking the mutex, so I thought it must be a problem of something else.
Best regards,
Limin
> Hello,
>
> for me this timeout makes cond_timedwait wait for 10 seconds:
> timespec timeout;
> timeout.tv_sec = time(0)+10;
> timeout.tv_nsec = 0;
>
> Try to check return code of the pthread_cond_timedwait. Probably you
> forgot to initialize mutex, or lock it before calling this function.
>
> FL> SYSTEMTIME now;
> FL> GetLocalTime( &now );
> FL> timeout.tv_sec = now.wSecond + sec;
> FL> timeout.tv_nsec = now.wMilliseconds*1E6 + nsec;
> this code will not work, because wSeconds - maximum value is 59. To
> use GetLocalTime you'll need to use all values starting from wYear..
> multiply them on number of seconds they have and add to each other.
>
>
> --
> Best regards,
> Dmitrii Sernii
>
>