index.doxy
SigCX provides a full API for threads, including classes for threads and various means of synchronisation (condition, mutex, semaphore) and a way to create thread-private data.
In the following, the concepts are described:
-
A thread is a execution context within a program. A multi-threaded program is a program that has multiple paths of execution (threads), which execute concurrently and share the same address space. This makes threads distinct from processes, as processes also execute concurrently, but have distinct address spaces. In general, there may be one or more threads per process.
In SigCX, you define a new thread by instantiating the Thread
class and passing it a slot of the threads work function. This slot is then called in the context of the new thread and executes in concurrency with the rest of the program.
-
A mutex (mutual exclusion) is a lock that can be obtained by exactly one execution context (thread) at a time. Any other attempt to obtain the lock results in blocking the thread that attempted to obtain it until the lock is released. Mutexes can be used to synchronize the access of shared data. Every thread accessing the data aquires a mutex before the access and releases it after the access. This way the data always accessed by only one thread and thus stays consistent.
-
A semaphore is an integer counter that allows two operations on it: up and down. The up operation simply increments the counter by one, the down blocks until an up operation is performed, if the counter is zero. After blocking (or if the counter was greater than zero), it decrements the counter.
-
A condition variable represents a condition that can be waited upon. The condition can be signalled to wake one thread waiting on it up, or 'broadcasted' to wake all waiting threads up.
-
Thread-private data is data that is local to a thread, that is, it can only be accessed from that thread. It behaves like a thread-split static.
A dispatcher is a facility where one can register handlers for various events and that invokes the handlers if these events happen. The dispatcher class in SigCX has support for input, output and exception handlers on file descriptors, timeout handlers and handlers for signals (those issued by raise()).
A SigCX tunnel is a device that has a source and destination end. It allows callbacks to be sent from the source to the destination end. As callbacks are received by the destination end, they are invoked (executed) in the order they are sent. Normally the callbacks are executed asynchronously, that means when you send a callback, you regain control immediatly. If this behaviour is not intended, e.g. you have to wait for the callbacks' result, you can tell the tunnel to execute the callback synchronously and have the send primitive wait until the callback has finished execution.
Tunnels can be used to establish communication channels between concurrent parts of the program, like between two threads. There is a ThreadTunnel
class in SigCX for this purpose. It is implemented using a UNIX pipe to transfer the callbacks from one thread to the other. But this class can also be used in single-threaded applications, where the callbacks can be defered until the dispatcher of the application handles them.
Go to the previous section or return to the
index.
Generated on Sun Apr 10 18:35:43 2005 for SigCX - SigC++ Extras by
1.4.2