class ThreadThread 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. |
| join(thread) | Waits for the specified thread to finish before proceeding. |
| yield() | Yields the processor to allow another thread to run. |
| getCurrentThread() | Returns the currently executing thread. |
Thread();
fork call.
Usage:
Thread thread;
string toString();
Usage:
string str = thread.toString();
Thread fork(void (*fn)()); Thread fork(void (*fn)(ClientType & data), ClientType & data);
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);
Usage:
join(thread);
void yield();
Usage:
yield();
Thread getCurrentThread();
Usage:
Thread self = getCurrentThread();