c - If sigwait() blocks, when is the accepted signal actually "selected"? -


there 2 real-time threads. first 1 has low priority , waiting possible signals in sigwait() (so signals blocked , sigmask passed function has signals enabled). second 1 has high priority , sends 2 signals first (low priority) thread - first sends sigrtmax , sigrtmin.

posix spec sigwait() ( http://pubs.opengroup.org/onlinepubs/9699919799/functions/sigwait.html ) says this:

if no signal in set pending @ time of call, thread shall suspended until 1 or more becomes pending.

[...]

should of multiple pending signals in range sigrtmin sigrtmax selected, shall lowest numbered one.

the sequence of events in real-time operating system that:

(h)...............signal(sigrtmax)===signal(sigrtmin)===... (l)===sigwait().........................................===       ^           ^                  ^                  ^       1           2                  3                  4 
  • (h) - high priority thread
  • (l) - low priority thread
  • . - thread not running
  • = - thread running

the 4 interesting points:

  1. low priority thread blocks on sigwait(), no signals pending, signals blocked, high priority thread not yet started;
  2. high priority thread starts , sends sigrtmax signal low priority thread, unblocked, not allowed run, high priority thread still running;
  3. high priority thread continues running , sends sigrtmin signal low priority thread, low priority thread still waiting run;
  4. high priority thread terminates, low priority thread allowed run , return sigwait() call;

now problem if both sigrtmin , sigrtmax signals pending @ same time, sigrtmin should "selected" first. i'm not sure @ point signal "selected" - selected kernel @ "2" or maybe selected code in sigwait() executed in low priority thread, @ "4"? that's why i'm not sure whether in scenario above, sigwait() call select sigrtmin or sigrtmax. maybe such details "implementation defined"?

the questions releated real-time operating system microcontrollers i'm developing ( https://github.com/distortec/distortos ). code "selects" signal during generation, @ "2" (my code return sigrtmax first), i'm no longer sure that's correct way it...

i'd consider scenario described race. so, well, outcome implementation defined.

signals should not used synchronisation. if order of receiving 2 signals important (to application) should take appropriate actions synchronise (them).


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -