Back to home page

darwin3

 
 

    


File indexing completed on 2024-12-17 18:31:06 UTC

view on githubraw file Latest commit add29e06 on 2018-01-31 20:35:05 UTC
b2518cdd0b Ed H*0001 /*
                0002  *
                0003  *
                0004  *  A PTHREADS convenience wrapper intended primarily for use with
                0005  *  gcc/g77 which does not support an "automatic" (here, meant as a
                0006  *  compiler-supported) threading mechanism.
                0007  *
                0008  */
                0009 
                0010 #ifdef HAVE_PTHREADS
                0011 
                0012 #include <stdlib.h>
                0013 #include <unistd.h>
                0014 #include <sys/stat.h>
                0015 #include <sys/types.h>
                0016 #include <sys/wait.h>
                0017 #include <errno.h>
                0018 #include <pthread.h>
                0019 
                0020 
                0021 void ptreentry_(int* myThid);
                0022 
                0023 pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
                0024 int             num_threads = 0;
                0025 
                0026 void *
                0027 threadfunc(void *parm)
                0028 {
                0029     int myThid;
                0030     int rc;
                0031 
                0032     rc = pthread_mutex_lock(&mutex);
                0033     num_threads++;
                0034     myThid = num_threads;
                0035     rc = pthread_mutex_unlock(&mutex);
                0036     ptreentry_(&myThid);
                0037 }
                0038 
                0039 void
                0040 ptinit_(int* nthreads)
                0041 {
                0042     int             i,j;
                0043     int             rc;
                0044     pthread_t       threadids[10];
                0045     pthread_attr_t  pta;
                0046 
                0047     pthread_attr_init(&pta);
                0048     pthread_attr_setdetachstate(&pta, PTHREAD_CREATE_JOINABLE);
                0049 
                0050     /*  start the threads  */
                0051     for (i=0; i<(*nthreads); i++)
                0052     rc = pthread_create(&threadids[i], &pta, threadfunc, NULL);
                0053 
                0054     /*  wait on thread termination  */
                0055     for (i=0; i<(*nthreads); i++)
                0056         rc = pthread_join(threadids[i], NULL);
                0057 }
                0058 
                0059 #endif /*  HAVE_PTHREADS  */