> First, I must say that this all concernes quite current > CURRENT (Jan 9 or so). I don't know if the same holds for > older versions. > > I'm kind of puzzled. > > I've a simple sample program (see at the bottom). It creates 10 > threads with start function start_my_thread(), and then runs the > same function in main(). So, we have 11 threads doing the same job. > > Function start_my_thread() just increments indefinitely counters > (each thread has its own counter). > > Program, when killed with SIGINT, prints all counters and exits. > > Now, as I understand, userspace threads in FreeBSD are preemptive. > So, though my 11 threads are all computational and do not do > any syscalls, sleeps, sched_yield, whatever -- newertheless, > the program should not be stuck in one thread. And it seems to > be sometimes true. But only sometimes! > > Depending on the phase of the moon (it seems) sometimes my > program gives (after ^C): > > ^C > Thread 0x00: 0 > Thread 0x01: 0 > Thread 0x02: 0 > Thread 0x03: 0 > Thread 0x04: 0 > Thread 0x05: 0 > Thread 0x06: 0 > Thread 0x07: 0 > Thread 0x08: 0 > Thread 0x09: 0 > Thread 0x0a: 488133092 OK, with everyones help (well, waiting for the right time of day ;-)), I was able to reproduce this. The initial threads last active time was not getting initialized to a sane value, causing negative computations of the threads timeslice depending on what time of day it was. Funny thing was that I added this change several times, but each time I somehow convinced myself that it wasn't needed. Try this patch - you may have to hand apply it as my sources are not yet up to date with the last round of changes that Jason made. Dan Eischen [EMAIL PROTECTED]
Index: uthread_init.c =================================================================== RCS file: /opt/b/CVS/src/lib/libc_r/uthread/uthread_init.c,v retrieving revision 1.21 diff -c -r1.21 uthread_init.c *** uthread_init.c 1999/12/29 15:44:59 1.21 --- uthread_init.c 2000/01/17 11:47:06 *************** *** 92,97 **** --- 92,98 ---- int mib[2]; struct clockinfo clockinfo; struct sigaction act; + struct timeval tv; /* Check if this function has already been called: */ if (_thread_initial) *************** *** 222,227 **** --- 223,233 ---- /* Initialize the owned mutex queue and count: */ TAILQ_INIT(&(_thread_initial->mutexq)); _thread_initial->priority_mutex_count = 0; + + /* Initialize last active time to now: */ + gettimeofday(&tv, NULL); + _thread_initial->last_active.tv_sec = tv.tv_sec; + _thread_initial->last_active.tv_usec = tv.tv_usec; /* Initialise the rest of the fields: */ _thread_initial->poll_data.nfds = 0;