public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
From: Ross Johnson <rpj@callisto.canberra.edu.au>
To: Allan Comar <acomar@commodity.com.br>
Cc: Pthreads-Win32 list <pthreads-win32@sources.redhat.com>
Subject: Re: pthread_cond_timedwait
Date: Sat, 11 Jun 2005 00:56:00 -0000	[thread overview]
Message-ID: <1118451365.9494.12.camel@desk.home> (raw)
In-Reply-To: <42A9F6CB.9070304@btinternet.com>

tests\stress1.c uses the following routine. The args are: a pointer to a
timespec instance and; the number of millisecs into the future. It
returns the first arg so you can call it directly from within
pthread_cond_wait's argument list:

struct timespec *
millisecondsFromNow (struct timespec * time, int millisecs)
{
  struct _timeb currSysTime;
  int64_t nanosecs, secs;
  const int64_t NANOSEC_PER_MILLISEC = 1000000;
  const int64_t NANOSEC_PER_SEC = 1000000000;

  /* get current system time and add millisecs */
  _ftime(&currSysTime);

  nanosecs = ((int64_t) (millisecs + currSysTime.millitm)) * NANOSEC_PER_MILLISEC;
  if (nanosecs >= NANOSEC_PER_SEC)
    {
      secs = currSysTime.time + 1;
      nanosecs %= NANOSEC_PER_SEC;
    }
  else
    {
      secs = currSysTime.time;
    }

  time->tv_nsec = (long)nanosecs;
  time->tv_sec = (long)secs;

  return time;
}

Ross

On Fri, 2005-06-10 at 21:23 +0100, Steve Croall (TIBCO) wrote: 
> Hi,
> 
> The timeout parameter you pass to pthread_cond_timedwait() is a struct 
> timespec type, which is defined in pthread.h, if HAVE_STRUCT_TIMESPEC is 
> not defined at build time.
> 
> struct timespec {
>          long tv_sec;
>          long tv_nsec;
> };
> 
> Just set the tv_nsec to the amount of nanoseconds required.  The pthread 
> source on Windows uses the following calculation to convert the above 
> structure to milliseconds:
> 
>    tmpAbsMilliseconds =  (int64_t)abstime->tv_sec * MILLISEC_PER_SEC;
>    tmpAbsMilliseconds += ((int64_t)abstime->tv_nsec + 
> (NANOSEC_PER_MILLISEC/2)) / NANOSEC_PER_MILLISEC;
> 
> Using the following defines:
> 
>    const int64_t NANOSEC_PER_MILLISEC = 1000000;
>    const int64_t MILLISEC_PER_SEC = 1000;
> 
> Steve.
> 
> Allan Comar wrote:
> > Hi all, I am needing something that I couldn't find in nowhere else, I am trying to use pthread_cond_timedwait but I want that the time that I need to wait is setted im milliseconds, I already could do in seconds and i am having a real hard time trying it in milliseconds. Any Ideas ? I am using MSVC6.0 with pthreads.
> > 
> 

  reply	other threads:[~2005-06-11  0:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-10 18:07 pthread_cond_timedwait Allan Comar
2005-06-10 20:23 ` pthread_cond_timedwait Steve Croall (TIBCO)
2005-06-11  0:56   ` Ross Johnson [this message]
  -- strict thread matches above, loose matches on Subject: below --
1999-09-09 10:51 pthread_cond_timedwait Bossom, John
1999-09-09  9:39 pthread_cond_timedwait Medina, Aurelio
1999-09-09  8:51 pthread_cond_timedwait Mikael.Ambrus
1999-09-09  9:21 ` pthread_cond_timedwait Scott Lightner

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=1118451365.9494.12.camel@desk.home \
    --to=rpj@callisto.canberra.edu.au \
    --cc=acomar@commodity.com.br \
    --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).