thrtest2.c
Go to the documentation of this file.
1 #include <thread.h>
2 #include <synch.h>
3 #include <math.h>
4 #include <sys/times.h>
5 #include <limits.h>
6 
7 mutex_t test_lock;
8 
9 int count=0;
10 
12 { mutex_lock(&test_lock);
13  printf("test1: %x mutex_locked\n", &test_lock);
14  sleep(3600/4); /* 15 minutes*/
15  mutex_unlock(&test_lock);
16  printf("test1: %x mutex_unlocked\n", &test_lock);
17  }
18 
19 
21 int n;
22 { printf("test2: want mutex_lock\n");
23  mutex_lock(&test_lock);
24  printf("test2: %x mutex_locked\n", &test_lock);
25  sleep(15); /* 15 seconds*/
26  mutex_unlock(&test_lock);
27  printf("test2: %x mutex_unlocked\n", &test_lock);
28  }
29 
30 main(argc,argv)
31 int argc;
32 char *argv[];
33 {
34  thread_t thrid[10];
35  int stat, *statp, stat2, s=1, exitstat, N;
36  struct tms t1,t2,t3,t4,t5,t6;
37  register int i;
38  int concurrency;
39 
40  stat=thr_self();
41  stat2=thr_min_stack();
42  if (argc>=2) sscanf(argv[1],"%d", &concurrency);
43  else concurrency=4;
44  if (argc>=3) sscanf(argv[2], "%d", &N);
45  else N=1000;
46 
47  thr_setconcurrency(concurrency);
48  printf("self=%d minstack=%x concurrency=%d CLK_TCK=%d\n\n",
49  stat, stat2, thr_getconcurrency(), CLK_TCK);
50 
51  times(&t1);
52  stat=thr_create(0,0,test1,&exitstat,THR_BOUND,&thrid[1]);
53  printf("test1 thread %d created\n", thrid[1]);
54  stat=thr_create(0,0,test2,&exitstat,THR_BOUND,&thrid[2]);
55  printf("test2 thread %d created\n", thrid[2]);
56 
57  thr_join(thrid[1], 0, 0);
58  thr_join(thrid[2], 0, 0);
59 
60  printf("joined\n");
61  }
62 
int thr_join(int tid, int *depature, void **status)
Definition: pthreads.c:75
GLfloat n[6][3]
Definition: cube.c:15
main(int argc, argv)
Definition: thrtest2.c:30
static int argc
Definition: transargv.c:56
test2(int n)
Definition: thrtest2.c:20
test1()
Definition: thrtest2.c:11
int count
Definition: thrtest2.c:9
short s
Definition: structsize.c:2
mutex_t test_lock
Definition: thrtest2.c:7
int thr_create(void *, size_t, void(*)(), void *, long, int *)
Definition: pthreads.c:43
unsigned int thr_self()
Definition: eus.c:25


euslisp
Author(s): Toshihiro Matsui
autogenerated on Thu Jun 6 2019 20:00:44