thrtest2.c
Go to the documentation of this file.
00001 #include <thread.h>
00002 #include <synch.h>
00003 #include <math.h>
00004 #include <sys/times.h>
00005 #include <limits.h>
00006 
00007 mutex_t test_lock;
00008 
00009 int count=0;
00010 
00011 test1()
00012 {   mutex_lock(&test_lock); 
00013     printf("test1: %x mutex_locked\n", &test_lock);
00014     sleep(3600/4);      /* 15 minutes*/
00015     mutex_unlock(&test_lock); 
00016     printf("test1: %x mutex_unlocked\n", &test_lock);
00017   }
00018 
00019 
00020 test2(n)
00021 int n;
00022 { printf("test2: want mutex_lock\n");
00023   mutex_lock(&test_lock);
00024   printf("test2: %x mutex_locked\n", &test_lock);
00025   sleep(15);    /* 15 seconds*/
00026   mutex_unlock(&test_lock); 
00027   printf("test2: %x mutex_unlocked\n", &test_lock);
00028   }
00029 
00030 main(argc,argv)
00031 int argc;
00032 char *argv[];
00033 {
00034   thread_t thrid[10];
00035   int stat, *statp, stat2, s=1, exitstat, N;
00036   struct tms t1,t2,t3,t4,t5,t6;
00037   register int i;
00038   int concurrency;
00039 
00040   stat=thr_self();
00041   stat2=thr_min_stack();
00042   if (argc>=2) sscanf(argv[1],"%d", &concurrency);
00043   else concurrency=4;
00044   if (argc>=3) sscanf(argv[2], "%d", &N);
00045   else N=1000;
00046 
00047   thr_setconcurrency(concurrency);
00048   printf("self=%d  minstack=%x concurrency=%d CLK_TCK=%d\n\n",
00049         stat, stat2, thr_getconcurrency(), CLK_TCK);
00050 
00051   times(&t1);
00052   stat=thr_create(0,0,test1,&exitstat,THR_BOUND,&thrid[1]);
00053   printf("test1 thread %d created\n", thrid[1]);
00054   stat=thr_create(0,0,test2,&exitstat,THR_BOUND,&thrid[2]);
00055   printf("test2 thread %d created\n", thrid[2]);
00056 
00057   thr_join(thrid[1], 0, 0);
00058   thr_join(thrid[2], 0, 0);
00059 
00060   printf("joined\n");
00061   }
00062 


euslisp
Author(s): Toshihiro Matsui
autogenerated on Thu Jun 6 2019 18:05:53