8
#include "src/private.h"
13
# define err(rc,msg,...) do { perror(msg); exit(rc); } while (0)
14
# define errx(rc,msg,...) do { puts(msg); exit(rc); } while (0)
17
#include "pthread_workqueue.h"
21
pthread_workqueue_t wq;
23
void additem(void (*func)(void *),
28
rv = pthread_workqueue_additem_np(wq, *func, arg, NULL, NULL);
30
errx(1, "unable to add item: %s", strerror(rv));
37
int *count = (int *) arg;
38
static const int nval = 5000;
42
/* Do some useless computation */
43
for (i = 0; i < nval; i++) {
46
for (j = 0; j < nval; j++) {
47
for (i = 0; i < nval; i++) {
63
printf("%s\n", (char *) msg);
64
if (strcmp(msg, "done") == 0)
73
printf("item %lu complete\n", (unsigned long) arg);
78
run_blocking_test(void)
80
const int rounds = 50;
82
for (unsigned long i = 0; i < rounds; i++) {
83
additem(lazy, (void *) i);
90
run_cond_wait_test(void)
92
const int rounds = 10;
94
sleep(3); /* Allow time for the workers to enter pthread_cond_wait() */
96
for (unsigned long i = 0; i < rounds; i++) {
97
additem(lazy, (void *) i);
108
for (int i = 0; i < 1024; i++) {
109
sprintf(buf, "%d", i);
110
additem(sleepy, strdup(buf));
111
additem(compute, NULL);
113
additem(sleepy, "done");
116
/* Try to overwhelm the CPU with computation requests */
118
run_stress_test(int rounds)
121
for (int i = 0; i < rounds; i++) {
122
additem(compute, &work_cnt);
126
puts("====== stress test complete =======");
133
printf("pthread_workqueue_create_np().. ");
134
rv = pthread_workqueue_create_np(&wq, NULL);
139
printf("stress test.. ");
143
//run_deadlock_test();
144
// run_cond_wait_test();
145
// run_blocking_test();
149
puts("All tests completed.\n");