public function timeBoxed(callable $code)
    {
        $existingHandler = pcntl_signal_get_handler(SIGALRM);

        $signal = pcntl_signal(SIGALRM, function (): void {
            throw new DeadlineException(sprintf("Timebox hit deadline of %d seconds", $this->timeout));
        });
        if (!$signal) {
            throw new LockAcquireException("Could not install signal");
        }
        $oldAlarm = pcntl_alarm($this->timeout);
        if ($oldAlarm != 0) {
            throw new LockAcquireException("Existing alarm was not expected");
        }
        try {
            return $code();
        } finally {
            pcntl_alarm(0);
            pcntl_signal_dispatch();
            pcntl_signal(SIGALRM, $existingHandler);
        }
    }