Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

Worker Thread Signal Handlers

AJ13
New Contributor I
1,019 Views
Hi everyone,

On Linux signal-handlers are thread-specific, and I would like to ensure that a signal handler is registered for each thread spawned by TBB for work.

Is there a sane way to do this?
0 Kudos
8 Replies
RafSchietekat
Valued Contributor III
1,019 Views
Have a look at task_scheduler_observer, but it does sound mighty suspicious what you're considering there...
0 Kudos
AJ13
New Contributor I
1,019 Views
If scheduler observer is called too frequently, initializing a signal handler is going to be rather wasteful considering it only needs to be called once at initialization. Unless the observer has some hook that is only called once?
0 Kudos
RafSchietekat
Valued Contributor III
1,019 Views
Hmm, but wouldn't you then also need a hook for the hook for the hook... :-)

It won't work unless you try it.
0 Kudos
AJ13
New Contributor I
1,019 Views
I know that using the observer will "work", and that is not what I was asking. The observer is going to be called as worker threads obtain work, so far as I can see, and that is extremely wasteful to put initialization code in that area that is frequently checked. Especially if the initialization code requires synchronization to ensure that this was a thread seen before to be initialized.

I appreciate your suggestion to look at the observer, but this is not what I want.
0 Kudos
RafSchietekat
Valued Contributor III
1,019 Views
It won't work unless you try it...

(2012-08-15 Added after #7) Sorry for not being more explicit earlier, but the calls happen very infrequently indeed (probably only twice in a worker thread's lifetime, perhaps more if an application thread explicitly uses different task_scheduler_init instances?).
0 Kudos
Anton_M_Intel
Employee
1,019 Views
Quoting AJ
The observer is going to be called as worker threads obtain work, so far as I can see, and that is extremely wasteful to put initialization code in that area that is frequently checked.

Why do you think an observer is called each time a thread obtains a work? Please read the documentation, oberver is guaranteed to be called once per thread after activation.

0 Kudos
AJ13
New Contributor I
1,019 Views
The documentation states: "A task_scheduler_observer permits clients to observe when a thread starts or stops participating in task scheduling." This is all the information provided.

Given this sentence, I inferred that the observer will be called during scheduling of tasks, in particular on the transition from an empty work-pool to a non-empty workpool. Perhaps this can be better worded?
0 Kudos
Anton_M_Intel
Employee
1,019 Views
I agree.. probably some hints lurk in callbacks description but the description is not clear enough.
0 Kudos
Reply