Worker Thread Signal Handlers

Worker Thread Signal Handlers

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?

9 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione

Have a look at task_scheduler_observer, but it does sound mighty suspicious what you're considering there...

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?

Hmm, but wouldn't you then also need a hook for the hook for the hook... :-)

It won't work unless you try it.

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.

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?).

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.

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?

I agree.. probably some hints lurk in callbacks description but the description is not clear enough.

Lascia un commento

Eseguire l'accesso per aggiungere un commento. Non siete membri? Iscriviti oggi