This is the mail archive of the
pthreads-win32@sources.redhat.com
mailing list for the pthreas-win32 project.
Re: pthread_cond_timedwait
- From: "Steve Croall (TIBCO)" <tibco dot croall at btinternet dot com>
- To: Allan Comar <acomar at commodity dot com dot br>
- Cc: pthreads-win32 at sources dot redhat dot com
- Date: Fri, 10 Jun 2005 21:23:39 +0100
- Subject: Re: pthread_cond_timedwait
- References: <9F29CF63398CDA4E8F98170E30D4230727C1D7@cs01i00388.commodity.com.br>
- Reply-to: scroall at tibco dot com
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.
--
J. Senior Software Engineer, Tibco Software Ltd.
T. +44 (0) 1792 360773
M. +44 (0) 7788 971394
E. scroall@tibco.com
W. www.tibco.com