25 printf(
"id=%d count=%d sinx=%f\n",
self,
count,
sinx);
35 printf(
"sematest exit\n");}
40 {
return((1000.0/CLK_TCK) *
41 ((t2->tms_utime-t1->tms_utime) + (t2->tms_stime-t1->tms_stime)));}
47 thread_t thrid[10001];
48 int stat, *statp, stat2,
s=1, exitstat, N;
49 struct tms t1,t2,t3,t4,t5,t6;
54 stat2=thr_min_stack();
55 if (argc>=2) sscanf(argv[1],
"%d", &concurrency);
57 if (argc>=3) sscanf(argv[2],
"%d", &N);
60 thr_setconcurrency(concurrency);
61 printf(
"self=%d minstack=%x concurrency=%d CLK_TCK=%d\n\n",
62 stat, stat2, thr_getconcurrency(), CLK_TCK);
66 stat=
thr_create(0,0,thr_exit,&exitstat,THR_BOUND,&thrid[i]);
67 if (i % 100 ==0) {printf(
"%d stat=%d\n", i, stat);}}
69 printf(
"creation time=%f max_thrid=%d\n",
ustime(&t1, &t2)/(
float)N,thrid[N-1]);
71 for(i=0; i<N; i++) {
thr_join(thrid[i], 0, 0);}
73 printf(
"join time=%f\n",
ustime(&t2, &t3)/(
float)N);
83 printf(
"sema switch time=%f\n",
ustime(&t3, &t4)/(
float)N);
97 printf(
"mutex_lock & unlock time=%f\n",
ustime(&t4, &t5)/((
float)N*5.0));
100 for (s=0; s<5; s++) {
103 if (stat!=0) exit(1);}
106 stat2=
thr_join(thrid[s], 0, &statp);
107 printf(
"stat2=%x stat=%x concurrency=%d\n", stat2, stat, thr_getconcurrency());}
int sema_init(sema_t *, unsigned int, int, void *)
int thr_join(int tid, int *depature, void **status)
float ustime(struct tms *t1, struct tms *t2)
int thr_create(void *, size_t, void(*)(), void *, long, int *)
int sema_post(sema_t *sem)