This is the mail archive of the
pthreads-win32@sourceware.org
mailing list for the pthreas-win32 project.
use of pthread_cond_timedwait
- From: gabbo <gabbo9lli at yahoo dot it>
- To: pthreads-win32 at sourceware dot org
- Date: Tue, 24 Jul 2007 20:35:25 +0200
- Subject: use of pthread_cond_timedwait
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