Table of Contents

WaitForShutdown Method

Blocks the calling thread until shutdown is requested, either by the operating system or by RequestShutdown.

Remarks

Intended for the main thread, once the server is up: it returns so that the caller can destroy the server in its finally block. The thread consumes no CPU while parked and is released as soon as the request arrives.

Returns immediately if shutdown has already been requested, so calling it again after it has returned costs nothing. Several threads may wait at the same time and all of them are released: on Windows the event is manual reset, and on POSIX each waiter puts the token back before returning, so the pipe stays readable for the next one. Sparkle.Host depends on this when more than one hosted block is registered, each parked in its own call.

On Windows this also covers the events for which the operating system terminates the process as soon as the handler returns (console close, logoff, shutdown): the handler stays blocked while the caller shuts down, up to the time limit the system allows.

Syntax

Unit: Sparkle.Host.Shutdown

procedure WaitForShutdown;