mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Andi Kleen <andi@firstfloor.org>
Cc: Frantisek Rysanek <Frantisek.Rysanek@post.cz>,
	linux-kernel@vger.kernel.org
Subject: Re: setitimer vs. threads: SIGALRM returned to which thread? (process master or individual child)
Date: Mon, 12 Apr 2010 00:09:59 +0200 (CEST)	[thread overview]
Message-ID: <alpine.LFD.2.00.1004120000330.18009@localhost.localdomain> (raw)
In-Reply-To: <87d3y5btdk.fsf@basil.nowhere.org>



On Sun, 11 Apr 2010, Andi Kleen wrote:

> "Frantisek Rysanek" <Frantisek.Rysanek@post.cz> writes:
> 
> > Yes, it used to be quite a relief to have Linux do the management of 
> > timers for me. Now I have two options to choose from:
> > 1) write my own "timer queueing" (timekeeping) code to order the 
> > timers for me in the master thread
> > 2) find another function, similar to setitimer(), that would function 
> > the way setitimer() used to work in the old days...
> 
> POSIX timers (timer_create et.al.) allow specifying the signal.
> 
> So if you use custom RT signals for each threads and block them in the
> threads you don't want them it should work. This would limit the
> maximum number of threads though because there's only a limited
> range of RT signals.
> 
> There are probably other ways to do this too, e.g. with some clever
> use of timerfd_create in recent kernels.
> 
> Or you could overwrite the clone in the thread library to not 
> set signal sharing semantics. This might have other bad side effects
> though.

Nonsense. Just use the right flags when creating the posix
timer. posix timers support per thread delivery of a signal, i.e. you
can use the same signal for all threads.

   sigev.sigev_notify = SIGEV_THREAD_ID | SIGEV_SIGNAL;
   sigev.sigev_signo = YOUR_SIGNAL;
   sigev.sigev_notify_thread_id = gettid();
   timer_create(CLOCK_MONOTONIC, &sigev, &timer);

That signal for that timer will not be delivered to any other thread
than the one specified in sigev.sigev_notify_thread_id as long as that
thread has not exited w/o canceling the timer.

Thanks,

	tglx

  parent reply	other threads:[~2010-04-11 22:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-09 19:48 Frantisek Rysanek
     [not found] ` <4BBF9B8F.3030106@gmail.com>
2010-04-10  7:26   ` Frantisek Rysanek
2010-04-11 20:56 ` Andi Kleen
2010-04-11 21:52   ` Davide Libenzi
2010-04-11 22:09   ` Thomas Gleixner [this message]
2010-10-17 20:42     ` Frantisek Rysanek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LFD.2.00.1004120000330.18009@localhost.localdomain \
    --to=tglx@linutronix.de \
    --cc=Frantisek.Rysanek@post.cz \
    --cc=andi@firstfloor.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®