Class Index [+]

    Quicksearch
    No matching classes.

    Caveats for implementing callbacks

    As with implementing signal handlers in C or most other languages, all code passed to must be reentrant. If you are not familiar with reentrancy, you need to read up on it at or elsewhere before reading the rest of this document.

    Most importantly, "thread-safety" does not guarantee reentrancy; and methods such as and which are commonly used for thread-safety even prevent reentrancy.

    An implementation detail of the Ruby VM

    The Ruby VM defers callbacks from running until it is safe for its internal data structures, but it does not know when it is safe for data structures in YOUR code. Ruby implements deferred signal handling by registering short C functions with only as signal handlers. These short C functions only do enough tell the VM to run callbacks registered via later in the main VM loop.

    Unsafe methods to call in blocks

    When in doubt, consider anything not listed as safe below as being unsafe.

    Commonly safe operations inside blocks

    • Assignment and retrieval of local, instance, and class variables

    • Most object allocations and initializations of common types including , , , , .

    • Common , , , operations which do not execute a block are generally safe; but beware if iteration is occurring elsewhere.

    • , (unless was given an unsafe block)

    • Thread::Queue#push and Thread::SizedQueue#push (since Ruby 2.1)

    • Creating a new via /Thread.start can used to get around the unusability of Mutexes inside a signal handler

    • is safe to use inside blocks passed to

    • arithmetic on and (`+', `-', '%', '*', '/')

      Additionally, signal handlers do not run between two successive local variable accesses, so shortcuts such as `+=' and `-=' will not trigger a data race when used on and classes in signal handlers.

    System call wrapper methods which are safe inside

    Since Ruby has wrappers around many the corresponding wrappers for many , , , and Socket methods are safe.

    (Incomplete list)

    is a service of and , purveyors of fine dance noise.