* use of pthread_cond_timedwait
@ 2007-08-10 2:33 gabbo
0 siblings, 0 replies; only message in thread
From: gabbo @ 2007-08-10 2:33 UTC (permalink / raw)
To: pthreads-win32
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2007-07-24 18:35 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-10 2:33 use of pthread_cond_timedwait gabbo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).