public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
From: Dmitrii Sernii <bogolt@gmail.com>
To: pthreads-win32@sources.redhat.com
Subject: Re: Problem with pthread_cond_timedwait()
Date: Tue, 27 Sep 2005 13:16:00 -0000	[thread overview]
Message-ID: <731315850.20050927161549@gmail.com> (raw)
In-Reply-To: <1402.130.192.136.198.1127819578.squirrel@130.192.136.198>

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

  reply	other threads:[~2005-09-27 13:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-27 11:13 Fu Limin
2005-09-27 13:16 ` Dmitrii Sernii [this message]
     [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
  -- strict thread matches above, loose matches on Subject: below --
2002-07-22 21:19 Nir Nizry
2002-07-24  0:31 ` Ross Johnson
2002-07-31  0:13 ` Ross Johnson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=731315850.20050927161549@gmail.com \
    --to=bogolt@gmail.com \
    --cc=pthreads-win32@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).