public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
From: gabbo <gabbo9lli@yahoo.it>
To: pthreads-win32@sourceware.org
Subject: use of pthread_cond_timedwait
Date: Fri, 10 Aug 2007 02:33:00 -0000	[thread overview]
Message-ID: <1185302125.3276.5.camel@localhost> (raw)

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

                 reply	other threads:[~2007-07-24 18:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1185302125.3276.5.camel@localhost \
    --to=gabbo9lli@yahoo.it \
    --cc=pthreads-win32@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).