public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
* Problem with pthread_cond_timedwait().
@ 2002-07-22 21:19 Nir Nizry
  2002-07-24  0:31 ` Ross Johnson
  2002-07-31  0:13 ` Ross Johnson
  0 siblings, 2 replies; 7+ messages in thread
From: Nir Nizry @ 2002-07-22 21:19 UTC (permalink / raw)
  To: pthreads-win32


Hello All,

I have a problem with pthread_cond_timedwait().
I have a system with 5 threads that in their main loop wait with a timeout
(timedwait) on a condition variable to be set.
what I get is, that sometimes a thread enters the pthread_cond_timedwait()
function, and doesn't come out, even if the timeout time arrives. after this
happens, the other threads get stuck in the mutex lock before entering the
pthread_cond_timedwait() as if the mutex is already locked.

I suspect that somehow either the pthread_cond_timedwait() function does not
release the mutex or does not return when the timeout occurs.

does someone have an idea' or know of such an incident (or maybe a bug in
pthread)??

Thanks.

Nir.

I added the code fraction where it get stucked (this is the ONLY place in
the code where the messageMutex is locked):


pthread_mutex_lock(messageMutex);

waitResult = 0;
while( m_theGeneralQueue->isEmpty() && !shouldStopThreadGlobalLoop &&
(waitResult != ETIMEDOUT))
	waitResult = pthread_cond_timedwait(newMessageEvent, messageMutex,
&timeout);

pthread_mutex_unlock(messageMutex);


-----------------------------------------

mailto:nir.nizry@bluesoft-inc.com

-----------------------------------------

^ permalink raw reply	[flat|nested] 7+ messages in thread
* Problem with pthread_cond_timedwait()
@ 2005-09-27 11:13 Fu Limin
  2005-09-27 13:16 ` Dmitrii Sernii
  0 siblings, 1 reply; 7+ messages in thread
From: Fu Limin @ 2005-09-27 11:13 UTC (permalink / raw)
  To: pthreads-win32

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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2005-09-28  8:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-22 21:19 Problem with pthread_cond_timedwait() Nir Nizry
2002-07-24  0:31 ` Ross Johnson
2002-07-31  0:13 ` Ross Johnson
2005-09-27 11:13 Fu Limin
2005-09-27 13:16 ` Dmitrii Sernii
     [not found]   ` <1130.130.192.136.198.1127830895.squirrel@130.192.136.198>
2005-09-27 15:49     ` Dmitrii Sernii
2005-09-28  8:38       ` Fu Limin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).