SafeFork

SafeFork

Offers some wrappers for the usage of fork to call expensive blocking functions without interrupting the main process and without the need to synchronize.

Usage Example:

import ocean.sys.SafeFork;

void main ( )
{
    auto dont_block = new SafeFork(&blocking_function);

    dont_block.call(); // call blocking_function

    if ( !dont_block.call() )
    {
        Stdout("blocking function is currently running and not done yet!");
    }

    while ( dont_block.isRunning() )
    {
        Stdout("blocking function is still running!");
    }

    if ( !dont_block.call() )
    {
        Stdout("blocking function is currently running and not done yet!");
    }

    dont_block.call(true); // wait for a unfinished fork and then call
                           // blocking_function without forking
}

Constructors

this
this(void delegate() dg)

Constructor

Members

Functions

call
bool call(bool block)

Call the delegate, possibly within a fork. Ensures that the delegate will only be called when there is not already a fork running. The fork exits after the delegate returned.

isRunning
bool isRunning()

Find out whether the fork is still running or not

Meta