10.3.3 Signalling threads
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
      • Multithreaded applications
        • Thread communication
          • Signalling threads
            • thread_signal/2
            • sig_pending/1
            • sig_remove/2
            • sig_block/1
            • sig_unblock/1
            • sig_atomic/1
    • Packages
Availability:built-in
[semidet]sig_atomic(:Goal)
Execute Goal as once/1 while blocking both thread signals (see thread_signal/2) and OS signals (see on_signal/3). The system executes some goals while blocking signals. These are:

  • The goal injected using thread_signal/2, i.e., signals do not interrupt a running signal handler.
  • The Setup call of setup_call_cleanup/3 and friends.
  • The Cleanup call of call_cleanup/2 and friends.
  • Compiling a file or loading a quick load file.

The call port of sig_atomic/1 does not handle signals. This may notably be used to prevent interruption of the catch/3 Recover goal. For example, we may ensure the recovery goal of a timeout is called using the code below. Without this precaution another signal may run before writeln/1 and raise an exception to prevent its execution. Note that catch/3 should generally not be used for cleanup of resources in case of an exception and thus it is typically fine if its Recover goal is interrupted. Use setup_call_cleanup/3 or one of the other predicates from the call_cleanup/2 family for cleanup.

    ...,
    catch(call_with_time_limit(Time, Goal),
          time_limit_exceeded,
          sig_atomic(writeln('Time limit exceeded'))).