signal handler priority issue

Daniel Eischen eischen at vigrid.com
Fri Jun 11 08:27:16 GMT 2004


On Fri, 11 Jun 2004, Sean McNeil wrote:

> Now here is something odd....
> 
> If I change the program a little, it acts completely different.  It
> actually works faster and looks correct.  I don't get it.  This is
> pretty much exactly what boehm-gc is doing.
> 
> static void
> pause_threads(void)
> {
>         int i;
> 
>         printf("Master: pausing all threads.\n");
>         for (i = 0; i < NUM_THREADS; i++) {
>                 pthread_kill(tids[i], SIGUSR1);
>         }
>         for (i = 0; i < NUM_THREADS; i++) {
>                 if (sem_wait(&semaphore) == -1)
>                         errno_abort("Wait on semaphore");
>         }
> }

Yeah, I almost coded it this way.  It seems to work faster because
the threads are true workers.  They're spinning wasting the CPU.
The timeslice is 10 or 20 msec, so you have to wait for each thread
to get timesliced out in order for it to have the signal delivered.
Instead of:

  thread 1 spin for 10msec
  master kill thread 1
  master wait thread for thread 1
  thread 2 spin for 10msec
  thread 3 spin for 10msec
  thread 4 spin for 10msec
  thread 5 spin for 10msec
  master wakeup from thread 1
  master kill thread 2
  thread 3 spin for 10msec
  thread 4 spin for 10msec
  thread 5 spin for 10msec
  master wakeup from thread 2
  master kill thread 3
  ...

you have

  threads running
  master thread gets his chance
  master kill thread 1
  master kill thread 2
  master kill thread 3
  master kill thread 4
  master kill thread 5
  thread 1 swapped back in, gets signal, pauses
  thread 2 swapped back in, gets signal, pauses
  thread 3 swapped back in, gets signal, pauses
  thread 4 swapped back in, gets signal, pauses
  thread 5 swapped back in, gets signal, pauses

-- 
Dan Eischen



More information about the freebsd-threads mailing list