phasync
The event loop / DeadlockException

Exception

DeadlockException

Coroutines wait, and nothing can ever wake them: the outermost run() throws this.

Introduction#

The loop finds this exactly, never by time: when no coroutine can run, no callback is queued, and no timer, timeout, idle() waiter, watched stream or signal handler (also one installed with pcntl_signal()) is left, every coroutine still waiting waits forever. The outermost run() then cancels its coroutines and the services with a CancelledException whose previous exception is this one, their finally blocks run, and it throws this, before anything else its coroutines threw. The message lists every waiting coroutine with the call it waits in and where that call is.

A coroutine waiting for a stream, a pipe or a socket is never part of a stall, since what it waits for can come from another process; so two coroutines each reading their end of a stream_socket_pair() wait forever. Nor is a stall of some coroutines while others make progress.

Class synopsis#

final class DeadlockException extends RuntimeException implements \Stringable, \Throwable {

}

Examples#

Example 1
try {
    phasync::run(function () {
        $done = new phasync\Util\WaitGroup();
        $done->add();
        $done->await();     // nobody calls done()
    });
} catch (phasync\DeadlockException $e) {
    echo $e->getMessage(), "\n";
}

See also#

  • phasync::runRuns $fn and returns its result once it and every coroutine started inside it have ended.
  • TimeoutExceptionA wait that gives up by itself