package affect

  1. Overview
  2. Docs
Streamlined and natural concurrency model for OCaml

Install

dune-project
 Dependency

Authors

Maintainers

Sources

affect-0.0.0.tbz
sha512=b328f6696e60c489da8cc2e8fad0537ca6634a39fc0c5de5840d4f98561f110617ef79ba8285ee8427dd99908c6b3d39114973598cddc5ded91abcce3b91b9a6

doc/affect.unix/Affect_unix/Unix/Signal/index.html

Module Unix.SignalSource

Waiting on signals.

Warning. This uses the OCaml signal handlers of Sys which are global variables. If you don't get what you want check that no other part of the program is trying to Sys.signal or Sys.set_signal.

Implementation note. Theoretically this should work reliably regardless on how signal delivery is configured in the program. The Signal.handler.Waiters signal handling mode integrates into the file descriptor watching infrastructure via a socket created with Unix.socketpair (self-pipe trick).

Waiting

Sourceval wait : Sys.signal -> unit

wait signal waits for the next occurence of signal and continues if and only if the handler of s is Waiters at signal occurence time.

Sourceval wait_any : Sys.signal list -> Sys.signal

wait_any signals waits for the next occurence of a signal in signals whose handler is Waiters at occurence time and continues with the signal that did.

Actions

Sourceval wait' : Sys.signal -> 'tag -> 'tag Affect.Action.t

wait' signal tag is the action used by wait and wait_any. The action invocation is enabled and synchronizes with tag whenever the next occurence of signal is delivered to the process and signal is set to be handled by Waiters at that instant.

Handling

Sourcetype handler =
  1. | Default
    (*

    Default signal hander, usually abort the program.

    *)
  2. | Ignore
    (*

    Ignore the signal.

    *)
  3. | Fun of Sys.signal -> unit
    (*

    Call the given function with the signal number.

    *)
  4. | Waiters
    (*

    Unblock functions waiting on the signal with the wait' action.

    *)
Sourceval set : Sys.signal -> handler -> unit

set signal h sets the handler of signal to h.

Sourceval set_and_restore : Sys.signal -> handler -> (unit -> 'a) -> 'a

set_and_restore signal b f gets the handler for signal as current, sets the handler of signal to b, calls f () and sets the handler of signal back to current after f returned or raised.

Warning. Signal handlers are global, there is no notion of scope here. If someone sets signal in parallel these changes will also be visible in f.

Formatting

pp formats signals for inspection.