Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Jun 2004 04:27:01 -0400 (EDT)
From:      Daniel Eischen <eischen@vigrid.com>
To:        Sean McNeil <sean@mcneil.com>
Cc:        freebsd-threads@freebsd.org
Subject:   Re: signal handler priority issue
Message-ID:  <Pine.GSO.4.10.10406110418180.12394-100000@pcnet5.pcnet.com>
In-Reply-To: <1086941779.10026.38.camel@server.mcneil.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.4.10.10406110418180.12394-100000>