1 #define TESTTHREADS 200
14 NOBUG_RESOURCE_HANDLE(rh
);
20 NOBUG_THREAD_ID_SET("thread");
22 NOBUG_RESOURCE_USER(rh
);
23 NOBUG_RESOURCE_USER_INIT(rh
);
24 NOBUG_RESOURCE_ENTER(NOBUG_ON
, ((struct testthread
*)nop
)->rh
, "threadfn", NOBUG_RESOURCE_WAITING
, rh
) { }
28 unsigned int seed
= (uintptr_t)nop
;
31 int r1
= (rand_r(&seed
)%100)*1000;
34 ECHO("first sleeping for %d usec", r1
);
39 ECHO("first busy for %d iterations", r1
*500);
40 for (volatile int i
=0; i
<r1
*500; ++i
)
47 NOBUG_RESOURCE_STATE (NOBUG_ON
, NOBUG_RESOURCE_EXCLUSIVE
, rh
) {}
49 int r2
= (rand_r(&seed
)%100)*1000;
52 ECHO("second sleeping for %d usec", r2
);
57 ECHO("second busy for %d iterations", r2
*500);
58 for (volatile int i
=0; i
<r2
*500; ++i
)
65 int r3
= (rand_r(&seed
)%100)*1000;
68 ECHO("third sleeping for %d usec", r3
);
73 ECHO("third busy for %d iterations", r3
*500);
74 for (volatile int i
=0; i
<r3
*500; ++i
)
83 NOBUG_RESOURCE_LEAVE(NOBUG_ON
, rh
) { }
90 NOBUG_THREAD_ID_SET("main");
96 struct testthread threads
[TESTTHREADS
];
98 for (int i
= 0; i
<TESTTHREADS
; ++i
)
100 NOBUG_RESOURCE_HANDLE_INIT(threads
[i
].rh
);
101 NOBUG_RESOURCE_ANNOUNCE(NOBUG_ON
, "thread", "test", &threads
[i
], threads
[i
].rh
)
103 if (!pthread_create(&threads
[i
].thread
, NULL
, threadfn
, &threads
[i
]))
105 ECHO("created thread");
109 ECHO("thread created failed");
115 for (int i
= 0; i
<TESTTHREADS
; ++i
)
119 NOBUG_RESOURCE_FORGET(NOBUG_ON
, threads
[i
].rh
)
121 if (!pthread_join(threads
[i
].thread
, &ret
))
123 ECHO("thread joined");
124 CHECK (ret
== &threads
[i
]);
128 ECHO("thread join failed");