thread.h

This interface exports a simple, platform-independent thread abstraction, along with simple tools for concurrency control.
Classes
Thread The Thread class encapsulates a lightweight process running in the same address space as the creator.
Lock This class represents a simple lock used to control concurrency.
Statement
synchronized(lock) Defines a critical section protected by the specified lock.
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.

Statement detail


synchronized (lock) . . .
Defines a critical section protected by the specified lock. The general strategy for using this facility is shown in the following paradigmatic pattern:

   synchronized (lock) {
      . . . statements in the critical section . . .
   }

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();