#!/usr/local/bin/rune -x # # Test overhead of non-threaded, threaded, and threaded+detached procedures. import "sys"; import ; alias stdio.File @stdout = stdio.stdout; int main(int ac, string_p *av) { int i; switch(ac) { case 1: # Normal call # for (i = 0; i < 1000000; ++i) test1(); break; case 2: # This makes a threaded call which does not detach # for (i = 0; i < 1000000; ++i) test2(); break; case 3: # Initial thread allocation overhead is high, force a # thread switch so the detached thread is able to run # and return before we create the next one so the thread # can be reused. We aren't testing uncached thead allocation # here. # for (i = 0; i < 1000000; ++i) { if (i % 10000 == 0) stdout->format("started %d\n", i); test3(i); } break; } stdio.stdout->show("finished all starts"); Thread.waitThreads(); } void test1() { } thread void test2() { } thread void test3(int i) { int l = i; int j; result; Thread.mssleep(10000); if (l % 100000 == 0) stdout->format("thread %d\n", l); for (;;) { # remove this to test cpu-bound thread switches Thread.mssleep(1); if (l % 10000 == 0) { stdout->format("loop %d\n", l); Thread.mssleep(1000); continue; } for (j = 0; j < 5000; ++j) ; } }