RFC: access to sigatomic_begin/end in Julia for non-interrupt-safe C calls #2759
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.
See also issue #2622. This adds Julia-callable
sigatomic_begin
/end
functions to temporarily deferSIGINT
(ctrl-c) handling, which is essential for long-running C calls that are not interrupt safe. These are wrapped in a higher-leveldisable_sigint() do ... end
construct. Moreover, it also allows one to re-enableSIGINT
handling within a disabled region, e.g. for Julia callbacks that can catch the exception.(This will enable my PyCall module, for example, to defer interrupts during Python calls, which are not interrupt safe. But if the Python has a Julia callback, that Julia callback can still catch
InterruptException
s, convert them to PythonKeyboardInterrupt
exceptions which are propagated back through Python and returned to the top-level Julia caller, which converts it back to anInterruptException
.)As mentioned in #2622, in the long run we will almost certainly want to make sigatomic the default for all
ccall
invocations (since C code cannot generally be assumed to be interrupt-safe), and if this is done directly in the LLVM code generation it can be much more efficient than callingdisable_sigint
from Julia. However, even when that is implemented, we will still want "manual" access tosigatomic_begin/end
in Julia in order to re-enable interrupts in callbacks as I mentioned above.