From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31695 invoked by alias); 24 Jul 2007 18:35:33 -0000 Received: (qmail 31687 invoked by uid 22791); 24 Jul 2007 18:35:33 -0000 X-Spam-Check-By: sourceware.org Received: from smtp007.mail.ukl.yahoo.com (HELO smtp007.mail.ukl.yahoo.com) (217.12.11.96) by sourceware.org (qpsmtpd/0.31) with SMTP; Tue, 24 Jul 2007 18:35:31 +0000 Received: (qmail 87945 invoked from network); 24 Jul 2007 18:35:28 -0000 Received: from unknown (HELO ?192.168.1.87?) (gabbo9lli@82.50.99.25 with plain) by smtp007.mail.ukl.yahoo.com with SMTP; 24 Jul 2007 18:35:28 -0000 X-YMail-OSG: CHgW88QVM1l_871lLXfdZZflQ8OeJQF1JFLRqXpDn1wUMVleENtidsD2ka8x.N2kkyU_4LKaOA-- Subject: use of pthread_cond_timedwait From: gabbo To: pthreads-win32@sourceware.org Content-Type: text/plain Date: Fri, 10 Aug 2007 02:33:00 -0000 Message-Id: <1185302125.3276.5.camel@localhost> Mime-Version: 1.0 X-Mailer: Evolution 2.10.2 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact pthreads-win32-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: pthreads-win32-owner@sourceware.org X-SW-Source: 2007/txt/msg00037.txt.bz2 hi, I would use pthread_cond_timedwait in windows ce. I have just compiled and linked the library for windows ce. I create a routine that calc timespec struct. The routine increase 1 sec (tv->sec). Routine blocks on this function (pthread_cond_timedwait) and don't continue. Routine is from tests/condvar2.c Compiler: visual studio for ARM. #include "test.h" #define TIMESPEC_TO_FILETIME_OFFSET (((LONGLONG)27111902 << 32) + (LONGLONG)3577643008) FILE *fp; char output[] = "results.txt"; void filetime_to_timespec(const FILETIME *ft, struct timespec *ts) { ts->tv_sec = (int)((*(LONGLONG *)ft - TIMESPEC_TO_FILETIME_OFFSET) / 10000000); ts->tv_nsec = (int)((*(LONGLONG *)ft - TIMESPEC_TO_FILETIME_OFFSET - ((LONGLONG)ts->tv_sec * (LONGLONG)10000000)) * 100); } void add_nano_second (struct timespec *t1, unsigned long nsec) { t1->tv_sec += 1; } int main() { struct timespec abstime = { 0, 0 }; FILETIME ft; SYSTEMTIME st; const DWORD NANOSEC_PER_MILLISEC = 1000000; if( (fp=fopen(output, "w"))==NULL){ fprintf(fp, "Cannot open file %d\n", output); exit(1); } assert(pthread_cond_init(&cv, NULL) == 0); assert(pthread_mutex_init(&mutex, NULL) == 0); assert(pthread_mutex_lock(&mutex) == 0); GetSystemTime(&st); SystemTimeToFileTime(&st, &ft); filetime_to_timespec(&ft, &abstime); add_nano_second(&abstime, 200*1000000); assert(pthread_cond_timedwait(&cv, &mutex, &abstime) == ETIMEDOUT); assert(pthread_mutex_unlock(&mutex) == 0); saluti gabriele novelli