• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Missing in sigaction
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Missing in sigaction


  • Subject: Re: Missing in sigaction
  • From: Greg Parker <email@hidden>
  • Date: Wed, 28 Mar 2012 10:25:13 -0700

On Mar 28, 2012, at 7:43 AM, Tilghman Lesher <email@hidden> wrote:
> 1/10th of a second is the maximum amount of time each thread is given
> to execute before the kernel preempts the thread, to allow another
> thread (or process) to execute.  It's heavily ingrained in all
> Unix-based systems, a somewhat arbitrary decision made in the 1960s by
> Dennis Ritchie, the father of Unix.  There have been attempts by
> others to modify that value, with results that caused performance to
> suffer, and the takeaway is that nobody has tried to modify the
> maximum timeslot since.  When you wait in a signal handler longer than
> the maximum length of a context switch, other processes (and not other
> threads in the same process) will get multiple timeslots, but the
> process in which a signal handler sleeps will be stuck, unable to do
> anything else, because _nothing_ in that process other than other
> signal handlers (if not blocked) can be invoked while that signal
> handler is still running.

I don't know much about UNIX history, but Darwin doesn't work this way. When a signal arrives, one thread handles the signal and other threads in that process continue unimpeded.

(I'd also expect Darwin to pre-empt threads much faster than 1/10s, and I'd expect "timeslots" to be a wild oversimplification on a multiprocessor system.)

% % clang test.c && ./a.out
signal
second thread still running
second thread still running
second thread still running
second thread still running
second thread still running
signal done

% cat test.c
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <pthread.h>

void *fn(void *arg)
{
    while (1) {
        printf("second thread still running\n");
        sleep(1);
    }
    return arg;
}

void handler(int arg)
{
    write(STDOUT_FILENO, "signal\n", 7);
    sleep(5);
    write(STDOUT_FILENO, "signal done\n", 7+5);
}

int main()
{
    pthread_t th;
    pthread_create(&th, NULL, &fn, NULL);

    signal(SIGUSR1, &handler);
    kill(getpid(), SIGUSR1);
}


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Missing in sigaction (From: Nat! <email@hidden>)
 >Re: Missing in sigaction (From: Tilghman Lesher <email@hidden>)
 >Re: Missing in sigaction (From: Nat! <email@hidden>)
 >Re: Missing in sigaction (From: Tilghman Lesher <email@hidden>)
 >Re: Missing in sigaction (From: Nat! <email@hidden>)
 >Re: Missing in sigaction (From: Tilghman Lesher <email@hidden>)

  • Prev by Date: Re: Missing in sigaction
  • Next by Date: Re: Missing in sigaction
  • Previous by thread: Re: Missing in sigaction
  • Next by thread: Re: Missing in sigaction
  • Index(es):
    • Date
    • Thread