From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17782 invoked by alias); 27 Sep 2005 13:16:09 -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 17208 invoked by uid 22791); 27 Sep 2005 13:15:53 -0000 Received: from xproxy.gmail.com (HELO xproxy.gmail.com) (66.249.82.192) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Tue, 27 Sep 2005 13:15:53 +0000 Received: by xproxy.gmail.com with SMTP id r21so1508745wxc for ; Tue, 27 Sep 2005 06:15:52 -0700 (PDT) Received: by 10.70.53.9 with SMTP id b9mr3005013wxa; Tue, 27 Sep 2005 06:15:52 -0700 (PDT) Received: from BOGGIEMOTH ( [217.26.152.52]) by mx.gmail.com with ESMTP id i33sm1442635wxd.2005.09.27.06.15.49; Tue, 27 Sep 2005 06:15:51 -0700 (PDT) Date: Tue, 27 Sep 2005 13:16:00 -0000 From: Dmitrii Sernii Reply-To: Dmitrii Sernii Message-ID: <731315850.20050927161549@gmail.com> To: pthreads-win32@sources.redhat.com Subject: Re: Problem with pthread_cond_timedwait() In-Reply-To: <1402.130.192.136.198.1127819578.squirrel@130.192.136.198> References: <1402.130.192.136.198.1127819578.squirrel@130.192.136.198> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-SW-Source: 2005/txt/msg00119.txt.bz2 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