Logo Search packages:      
Sourcecode: djvulibre version File versions

GThread Class Reference

#include <GThreads.h>

List of all members.

Detailed Description

Thread class. A multithreaded process is composed of a main execution thread and of several secondary threads. Each secondary thread is represented by a GThread# object. The amount of memory required for the stack of a secondary thread is defined when the GThread# object is constructed. The execution thread is started when function {GThread::create} is called. The destructor of class GThread waits until the thread terminanes. Note that the execution can be terminated at any time (with possible prejudice) by calling {GThread::terminate}.

Several static member functions control the thread scheduler. Function {GThread::yield} relinquishes the processor to another thread. Function {GThread::select} (COTHREADS# only) provides a thread-aware replacement for the well-known unix system call select#.

{ Note} --- Both the copy constructor and the copy operator are declared as private members. It is therefore not possible to make multiple copies of instances of this class, as implied by the class semantic.

Definition at line 230 of file GThreads.h.


Files #"GThreads.h"# and #"GThreads.cpp"# implement common entry points for multithreading on multiple platforms. Each execution thread is represented by an instance of class {GThread}. Synchronization is provided by class {GMonitor} which implements a monitor (C.A.R Hoare, Communications of the ACM, 17(10), 1974).

The value of compiler symbol THREADMODEL# selects an appropriate implementation for these classes. The current implementation supports the following values: {description} [-DTHREADMODEL=NOTHREADS] Dummy implementation. This is a good choice when the multithreading features are not required, because it minimizes the portability problems. This is currently the default when compiling under Unix. [-DTHREADMODEL=WINTHREADS] Windows implementation. This is the default when compiling under Windows. [-DTHREADMODEL=MACTHREADS] Macintosh implementation, which is based on the MacOS cooperative model. The current implementation does not yet fully support synchronization. This is the default when compiling under MacOS. [-DTHREADMODEL=POSIXTHREADS] Posix implementation. This implementation also supports DCE threads. The behavior of the code is subject to the quality of the system implementation of Posix threads. [-DTHREADMODEL=COTHREADS] Custom cooperative threads. These custom threads do not redefine system calls. Before executing a potentially blocking system function, each thread must explicitly check whether it is going to block and yield control explicitly if this is the case. This code must be compiled with a patched version of egcs-1.1.1 {http://egcs.cygnus.com}. The patch addresses exception thread-safety and is provided in #"@Tools/libgcc2.c.diff"#. Once you get the right compiler, this implementation is remarkably compact and portable. A variety of processors are supported, including mips, intel, sparc, hppa, and alpha. [-DTHREADMODEL=JRITHREADS] Java implementation hooks. Multi-threading within a Netscape plugin can be tricky. A simple idea however consists of implementing the threading primitives in Java and to access them using JRI. The classes just contain a JRIGlobalRef. This is not a real implementation since everything (Java code, native functions, stubs, exception thread safety) must be addressed by the plugin source code. Performance may be a serious issue. {description}

{ Portability}: The simultaneous use of threads and exceptions caused a lot of portability headaches under Unix. We eventually decided to implement the COTHREADS cooperative threads (because preemptive threads have more problems) and to patch EGCS in order to make exception handling COTHREAD-safe.

Portable threads

L\'eon Bottou <leonb@research.att.com> -- initial implementation.\ Praveen Guduru <praveen@sanskrit.lz.att.com> -- mac implementation.
From: Leon Bottou, 1/31/2002 Almost unchanged by Lizardtech. GSafeFlags should go because it not as safe as it claims.

GThreads.h,v 1.10 2003/11/07 22:08:21 leonb Exp

 GThread (int stacksize=-1)
void terminate ()
 ~GThread ()
static void * current ()
static int yield ()

Public Member Functions

int create (void(*entry)(void *), void *arg)

Public Attributes

void * xarg
void(* xentry )(void *)

Private Member Functions

 GThread (const GThread &)
GThreadoperator= (const GThread &)

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index