Block signal delivery to OpenBLAS-spawned threads #4054
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Otherwise non-threaded applications may use signals in a way that is currently affected by OpenBLAS launching threads.
For example, it is not uncommon for an application main loop to block signals when busy, then unblock those signals while waiting for IO. (see the sigmask argument to
ppoll(2)
)Signals that arrive during
ppoll(2)
will interrupt the system call, and allow the application to handle any consequences of that signal arriving. Normally (in a single threaded process), on delivery of an externally generated signal such as SIGALRM, SIGCHLD, SIGIO the main loop will be awoken. If the thread is otherwise busy, then the signal will be maintained as pending, and will be delivered when the application next enters its idle state (egppoll
), unblocking signals again.OpenBLAS creates threads during initialization. Such threads inherit their signal masks from the thread that creates them, and, if that loading happens very early in the lifetime of a process, all signals are nominally unblocked in the these threads
Later, if the "main" thread is running with signals blocked when a signal is sent to the process, the kernel will deliver it to another thread in the process if it is not currently blocking that signal, in our case, to one of the OpenBLAS threads.
This means that by creating threads with open signal masks, OpenBLAS is potentially interfering with the normal operation of programs that are otherwise non-threaded.
Instead, we should block all signals before starting new threads from
blas_thread_init
, and then restore the signal mask as it was, so the launched threads do not participate in signal delivery and processing.