Multi-Threaded Programming in C++ by Mark Walmsley PhD, BSc (auth.)

By Mark Walmsley PhD, BSc (auth.)

Show description

Read Online or Download Multi-Threaded Programming in C++ PDF

Best programming: programming languages books

Prototype and Scriptaculous: Taking the Pain out of JavaScript

This brief minimize demonstrates the best way to use Prototype for quite a lot of initiatives, together with occasion dealing with, DOM processing, string and shape technique, and Ajax communications. It explores Scriptaculous' visible results library, from pulsate to squish to fold and past. desire interface elements? you can find shape autocompletion in addition to drag and drop aid.

Fast Track to Sun Certified Java Program

If you want to profit the recent good points in Java SE five. zero and cross the sunlight qualified Java Programmer improve examination (CX-310-056), then this ebook is for you. It covers the entire Java SE five. zero new gains required within the examination. you do not need to examine the prevailing positive factors that you simply already be aware of. 117 evaluation questions and ridicule examination questions are integrated.

Additional info for Multi-Threaded Programming in C++

Example text

2 The EVENT Class The EVENT class encapsulates the functionality of an event as supported by the operating system in order to hide the variations which occur between different implementations: class EVENT public: EVENT(int = TRUE); -EVENT (void) ; void Signal(void); void Wait(void); void Reset(void); int Test (void) ; } ; Events 49 The constructor takes a single boolean parameter to indicate whether the event is 'automatic' or 'manual' - by default an automatic event is created. The difference in the two types of event is how the Wai t () function affects the internal state of the event - the following figure illustrates the point signalled non-signalled ~ I ---- ---------------------- I I I .

The solution, of course, is to serialize the printing of the various greetings and the first step is to derive a new action class from the ATOMIC ACTION base class: HELLO ACTION : pub1ic ATOMIC_ACTION pub1ic: virtua1 void Execute(void*); a~ass }; The HELLO_ACTION class must provide a definition of the Execute () function: void HELLO_ACTION::Execute(void* param) char letter = (char) (1onq)param; printf("%c",letter); The action specified is to print a single character - the HELLO class Run ( ) function can now build a list of such actions into an atomic operation.

Now only one thread at a time can execute the code between the Acquire () and Release () calls - a portion of code bracketed in this way is sometimes referred to as a 'critical region' or 'critical section' but in this book the term 'mutex (protected code) block' is applied. Now if simultaneous calls to GetID () are made by threads A and B then whilst thread A is executing the code within the mutex block thread B must wait in the Acquire () function. A typical sequence of events might be as follows: thread A thread B store 0 increment Counter store 1 increment Counter return 1 return 0 There is still some degree of unpredictability but now one thread will always obtain the value 0, the other thread will always obtain the value 1 and the final value of the E:ounter variable will always be 2.

Download PDF sample

Rated 4.62 of 5 – based on 23 votes