OpenGL Vizserver Reference Page


NAME
vsThread - portable thread interface

HEADER FILE
#include <vizserver/vsThread.h>

PUBLIC METHOD SUMMARY

   Creation and destruction
vsThread (  );
~vsThread (  );

   Usage
vsStatus threadStart ( Routine* entryPoint, void* arg);
static ID getID (  );
static void yield (  );
static void threadExit (  );

   Thread private data
static vsStatus createKey ( Key& key, DataDestructor destructor);
static vsStatus setSpecific ( Key key, void* data);
static void* getSpecific ( Key key);
static unsigned int getNumProcessors (  );
static int setMaxParallelThreads ( unsigned int t=getNumProcessors());
static int getMaxParallelThreads ( void);

CLASS DESCRIPTION
The vsThread class is used to create a parallel thread of execution. Used in conjunction with the mutual exclusion primitives vsLock, vsSemaphore and their variants, this class provides a reasonably complete, OS independent multi-threading interface that is useful for Vizserver based applications.

METHOD DESCRIPTIONS

   vsThread()
vsThread (  );

Creates a vsThread instance without starting the actual thread.

   ~vsThread()
~vsThread (  );

Destroys the vsThread instance. This does not force the actual thread to exit however.

   createKey()
static vsStatus createKey ( Key& key, DataDestructor destructor);

Creates a new private data key for the process. The returned key can be used by all threads within the process to set/access their private data. When the thread is destroyed, the destructor function is invoked with the thread specific data (see setSpecific() passed as the argument. This exists to simplify thread exits.

   getID()
static ID getID (  );

Returns the unique identifier for the calling thread.

   getMaxParallelThreads()
static int getMaxParallelThreads ( void);

Gets the maximum number of threads that can run in parallel (on multiple CPUs) for this process. Parallel means "simultaneously", but this doesn't affect thread concurrency. A return value of 0 means that the maximum number of parallel threads is unknown and adjusted to default by the kernel.

   getNumProcessors()
static unsigned int getNumProcessors (  );

Returns the number of available processors on the system.

   getSpecific()
static void* getSpecific ( Key key);

Returns the thread specific data with key for the calling thread.

   setMaxParallelThreads()
static int setMaxParallelThreads ( unsigned int t=getNumProcessors());

Sets up the maximum number of threads that can run in parallel (on multiple CPUs) for this process. Parallel means "simultaneously", but this doesn't affect thread concurrency. The default parameter would be the number of CPUs in the system.

   setSpecific()
static vsStatus setSpecific ( Key key, void* data);

Sets the thread specific data with key to data for the calling thread. The caller should ensure that previous values are correctly cleaned up, since this call does not.

   threadExit()
static void threadExit (  );

Terminates the calling thread.

   threadStart()
vsStatus threadStart ( Routine* entryPoint, void* arg);

Start a parallel thread of execution. The thread starts executing by calling the entryPoint routine and passing arg to it.

   yield()
static void yield (  );

Yields the current thread schedule.

SEE ALSO
vsLock, vsSemaphore