2 * Copyright (c) 2009 Mark Heily <mark@heily.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include "../config.h"
25 #include <sys/event.h>
27 /* Number of threads to create */
28 static const int nthreads = 64;
30 /* Number of iterations performed by each thread */
31 static const int nrounds = 1000000;
33 //pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
36 test_kqueue_conc(void)
40 for (i = 0; i < 256; i++) {
49 test_harness(void *arg)
59 printf("thread %d runs %d\n", id, id % 4);
62 for (i = 0; i < nrounds; i++) {
64 case 0: test_evfilt_user(kqfd);
66 case 1: test_evfilt_read(kqfd);
68 case 2: test_evfilt_timer(kqfd);
70 case 3: test_evfilt_vnode(kqfd);
73 printf("thread %d round %d / %d\n", id, i, nrounds);
75 printf("thread %d done\n", id);
79 main(int argc, char **argv)
81 pthread_t tid[nthreads];
84 for (i=0; i<nthreads; i++) {
85 if (pthread_create(&tid[i], NULL, test_harness, (void *)i) != 0)
86 err(1, "pthread_create");
88 for (i=0; i<nthreads; i++) {
89 if (pthread_join(tid[i], NULL) != 0)
90 err(1, "pthread_join");
92 printf("\n---\n+OK All tests completed.\n");