Date: Thu, 26 Jun 2003 10:32:02 -0700 From: Alex Boisvert <boisvert@intalio.com> To: freebsd-threads@freebsd.org Subject: libkse / libthr bugs? Message-ID: <3EFB2E12.3080504@intalio.com>
next in thread | raw e-mail | index | archive | help
Hi, I written a small test case (see source below), which I've run against both libkse and libthr. I'm using -CURRENT as of last Tuesday and running on a Dual Athlon MP 1.2 GHz (Tyan Thunder K7 motherboard). With libkse, the program runs most of the time (say, about 9 times out of 10) but sometimes hang and, interestingly, prints an "F" character to the console -- but that "F" character is never printed by the application itself! (see source) Here are two examples of when it hangs: bipolar:boisvert:~/prog/pthread:48 gcc -g -lkse -o foo2 foo2.c bipolar:boisvert:~/prog/pthread:49 ./foo2 1000 Using 1000 threads (parameter) bar 0 bar 1 bar 2 Fbar 3 ^C bipolar:boisvert:~/prog/pthread:50 (Notice the "F" on the last line, before I had to use CTRL-C to terminate the application). Also, sometimes I get: bipolar:boisvert:~/prog/pthread:65 ./foo2 1000 Using 1000 threads (parameter) F ^C bipolar:boisvert:~/prog/pthread:66 I also tried the same test case with libthr and got a different behavior: bipolar:boisvert:~/prog/pthread:141 gcc -g -lthr -o foo2 foo2.c bipolar:boisvert:~/prog/pthread:142 ./foo2 1000 Using 1000 threads (parameter) bar 0 foo2: Unknown error: 0 bipolar:boisvert:~/prog/pthread:143 In this case, the behavior is more easily reproductible. So, maybe you can help me figure out if my test case is somehow invalid or these are genuine problems within the threading libraries... cheers, alex ----------- foo2.c #include <stdlib.h> #include <stdio.h> #include <pthread.h> void *foo(void *); typedef struct { int number; } arg_t; /** * Simple test case for the thread system. Start "n" threads, * and join them afterwards. */ int main( int argc, char** argv) { pthread_t* threads; arg_t* args; void* ret; int n; int i; if ( argc > 1 ) { n = strtoimax( argv[1], NULL, 10 ); printf( "Using %d threads (parameter)\n", n ); } else { n = 5; printf( "Using %d threads (default)\n", n ); } // initialize random number generator srandomdev(); threads = (pthread_t*) malloc( sizeof(pthread_t) * n ); args = (arg_t*) malloc( sizeof(arg_t) * n ); // start n threads for ( i=0; i<n; i++ ) { args[i].number = i; if (pthread_create(&threads[i], NULL, foo, &args[i]) != 0) { err(1, NULL); } } // join threads for ( i=0; i<n; i++ ) { if (pthread_join(threads[i], &ret) != 0) { err(1, NULL); } } free( threads ); return (0); } void * foo(void *v) { int i; arg_t arg; arg = *(arg_t*)v; // simulate some CPU-intensive calculations int loops = ( ( random() % 100 ) + 1 ) * 100; for (i=1;i<loops;i++) { int a = i * (random() % 11); int b = a * (random() % 13); int c = b * (random() % 17); int d = c * (random() % 23); } printf("bar %d\n", arg.number); return (NULL); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3EFB2E12.3080504>