Mutual exclusion and threading


Introduction

           QUANTA allows you to encapsulate mutual exclusion in a C++ object. You can also write threaded programs with the QUANTA. The QUANTAts_thread-related classes are intended to be simplified versions of the globus/pthread interfaces so that beginners can quickly create threaded programs. For greater control over threads use the globus thread API which is very similar to the pthreads API.

More about Mutual Exclusion?


QUANTA classes used

    QUANTAts_mutex_c

                This class provides lock() and unlock() methods on a mutex object to assign access on the resource. setMutexDebug() can turn on debug messages or set them off. setMutexDebugMesg() can print the debug message whenever lock or unlock is performed.

    QUANTAts_thread_c

                The create() method can create a new thread and execute the function to be performed in a separate thread.

                The thread_demo.cxx program creates a mutual exclusion object 'quantaMutex' and a threads object 'quantaThread' the demos sets up 100 threads and executes the function threadedFunction() in each thread (which simply prints out the thread number). The threadedFunction() locks and unlocks the mutex object. 


Usage

         To run the demo type :
                thread_demo

Output

            You can see 100 threads being created.

for more information: Post your questions online on the Quanta forum page.