From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Sat, 9 Dec 1995 00:22:44 -0500 From: Scott Schwartz schwartz@galapagos.cse.psu.edu Subject: more microbenchmarks, threads Topicbox-Message-UUID: 378bee8c-eac8-11e9-9e20-41e7f4b1d025 Message-ID: <19951209052244.glUNMCgKizwFbvls9TTpujdMI8uUfXoim-Qom1Rm66w@z> Over on comp.programming.threads there's been some discussion of thread performance under solaris based on some small programs that exercise thread creation. (See Steve Rogers' Message-ID: <1995Dec6.125003.2562@picker.com>, and subsequent.) Inspired to comparare, I ran one of those programs on a Sparcstation 2 with Solaris. Then I translated it---accurately I hope, although rendezvous() isn't quite the same as a semaphore---for Plan 9, and ran it on another SS2. The results were about the same, except that under Plan 9 real time was much greater than user+system. Is the time getting lost during scheduling, or something like that? term% time k.out COUNTER: 10000 0.20u 9.78s 43.26r k.out #include #include #include #define ITERATIONS 1000 #define MAX_THREAD 10 static Lock mutex; static int counter = 0; void thread_func(void) { lock(&mutex); counter++; if ((counter % MAX_THREAD) == 0) { rendezvous(0, 1); } unlock(&mutex); } int thr_create (void (*func)(void)) { int pid = rfork(RFPROC|RFMEM|RFNOWAIT); switch (pid) { case -1: fprint(2, "rfork failed: %r\n"); exits("rfork"); case 0: (*func)(); exits(0); default: return pid; } } void main(int argc, char *argv[]) { int ii, jj; int pid; counter = 0; lockinit(); for ( ii = 0; ii < ITERATIONS; ii++ ) { for ( jj = 0; jj < MAX_THREAD; jj++ ) { pid = thr_create(thread_func); } rendezvous(0, 0); } fprint(2, "COUNTER: %d\n", counter); exits(0); }