skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

trypthread.c (527B)


      1 /* ISC license. */
      2 
      3 #include <time.h>
      4 #include <pthread.h>
      5 
      6 void *pstart (void *arg)
      7 {
      8   (void)arg ;
      9   return 0 ;
     10 }
     11 
     12 int main (void)
     13 {
     14   pthread_t th ;
     15   pthread_attr_t attr ;
     16   pthread_cond_t cond = PTHREAD_COND_INITIALIZER ;
     17   pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER ;
     18   struct timespec ts = { .tv_sec = 1, .tv_nsec = 0 } ;
     19   void *p ;
     20   int e = pthread_attr_init(&attr) ;
     21   e = pthread_create(&th, &attr, &pstart, 0) ;
     22   e = pthread_cond_timedwait(&cond, &mutex, &ts) ;
     23   e = pthread_join(th, &p) ;
     24   return 0 ;
     25 }