The SimpleCxxLib package


#include "thread.h"

class Thread

This class encapsulates a lightweight process running in the same address space as the creator. The class itself is opaque and is manipulated by top-level functions as illustrated in the following paradigm:
   Thread child = fork(fn);
   ... code for the parent thread ...
   join(child);
This code calls fn so that it runs in parallel with the parent code.
Constructor
Thread() Creates an inactive thread variable that will typically be overwritten by the result of a fork call.
Method
toString() Converts the thread to a string.
Functions
fork(fn)
fork(fn, data) 
Creates a child thread that calls fn in an address space shared with the current thread.
getCurrentThread() Returns the currently executing thread.
join(thread) Waits for the specified thread to finish before proceeding.
yield() Yields the processor to allow another thread to run.

Constructor detail


Thread();
Creates an inactive thread variable that will typically be overwritten by the result of a fork call.

Usage:

Thread thread;

Method detail


string toString();
Converts the thread to a string.

Usage:

string str = thread.toString();

Function detail


Thread fork(void (*fn)());
Thread fork(void (*fn)(ClientType & data), ClientType & data);
Creates a child thread that calls fn in an address space shared with the current thread. The second form makes it possible to pass an argument to fn, which may be of any type.

Usage:

Thread child = fork(fn);
Thread child = fork(fn, data);

void join(Thread & thread);
Waits for the specified thread to finish before proceeding.

Usage:

join(thread);

void yield();
Yields the processor to allow another thread to run.

Usage:

yield();

Thread getCurrentThread();
Returns the currently executing thread.

Usage:

Thread self = getCurrentThread();