From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32275 invoked by alias); 11 Jun 2005 00:56:12 -0000 Mailing-List: contact pthreads-win32-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: pthreads-win32-owner@sources.redhat.com Received: (qmail 32146 invoked by uid 22791); 11 Jun 2005 00:56:06 -0000 Received: from canyonero.dot.net.au (HELO canyonero.dot.net.au) (202.147.68.14) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Sat, 11 Jun 2005 00:56:06 +0000 Received: from [203.129.49.13] (helo=ppp-49-13.grapevine.net.au) by canyonero.dot.net.au with esmtp (Exim 3.35 #1 (Debian)) id 1DguI4-0007rY-00; Sat, 11 Jun 2005 10:56:00 +1000 Subject: Re: pthread_cond_timedwait From: Ross Johnson To: Allan Comar Cc: Pthreads-Win32 list In-Reply-To: <42A9F6CB.9070304@btinternet.com> References: <9F29CF63398CDA4E8F98170E30D4230727C1D7@cs01i00388.commodity.com.br> <42A9F6CB.9070304@btinternet.com> Content-Type: text/plain Date: Sat, 11 Jun 2005 00:56:00 -0000 Message-Id: <1118451365.9494.12.camel@desk.home> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-SW-Source: 2005/txt/msg00111.txt.bz2 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. > > >