URI:
       tpthreadloop.c - plan9port - [fork] Plan 9 from user space
  HTML git clone git://src.adamsgaard.dk/plan9port
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
       tpthreadloop.c (496B)
       ---
            1 #include <pthread.h>
            2 #include <utf.h>
            3 #include <fmt.h>
            4 
            5 pthread_key_t key;
            6 
            7 void
            8 pexit(void *v)
            9 {
           10         int s;
           11 
           12         pthread_setspecific(key, (void*)1);
           13         switch(fork()){
           14         case -1:
           15                 fprint(2, "fork: %r\n");
           16         case 0:
           17                 _exit(0);
           18         default:
           19                 wait(&s);
           20         }
           21         pthread_exit(0);
           22 }
           23 
           24 int
           25 main(int argc, char *argv[])
           26 {
           27         int i;
           28         pthread_t pid;
           29 
           30         pthread_key_create(&key, 0);
           31         for(i=0;; i++){
           32                 print("%d\n", i);
           33                 if(pthread_create(&pid, 0, pexit, 0) < 0){
           34                         fprint(2, "pthread_create: %r\n");
           35                         abort();
           36                 }
           37         }
           38 }