kviewshell
GThread Class Reference
Thread class. More...
#include <GThreads.h>
Public Member Functions | |
int | create (void(*entry)(void *), void *arg) |
Public Attributes | |
void * | xarg |
void(* | xentry )(void *) |
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 From: Leon Bottou, 1/31/2002 Almost unchanged by Lizardtech. GSafeFlags should go because it not as safe as it claims.
| |
GThread (int stacksize=-1) | |
void | terminate () |
~GThread () | |
static void * | current () |
static int | yield () |
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.
Constructor & Destructor Documentation
GThread::GThread | ( | int | stacksize = -1 |
) | [inline] |
Constructs a new thread object.
Memory is allocated for the thread, but the thread is not started. Argument stacksize# is used by the COTHREADS# model only for specifying the amount of memory needed for the processor stack. A negative value will be replaced by a suitable default value of 128Kb. A minimum value of 32Kb is silently enforced.
Definition at line 440 of file GThreads.h.
GThread::~GThread | ( | void | ) | [inline] |
Destructor.
Destroying the thread object while the thread is running is perfectly ok since it only destroys the thread identifier. Execution will continue without interference.
Definition at line 441 of file GThreads.h.
Member Function Documentation
int GThread::create | ( | void(*)(void *) | entry, | |
void * | arg | |||
) |
Starts the thread.
The new thread executes function entry# with argument arg#. The thread terminates when the function returns. A thread cannot be restarted after its termination. You must create a new GThread# object.
Definition at line 127 of file GThreads.cpp.
void * GThread::current | ( | ) | [inline, static] |
Returns a value which uniquely identifies the current thread.
Definition at line 444 of file GThreads.h.
void GThread::terminate | ( | ) | [inline] |
Terminates a thread with extreme prejudice.
The thread is removed from the scheduling list. Execution terminates regardless of the execution status of the thread function. Automatic variables may or may not be destroyed. This function must be considered as a last resort since memory may be lost.
Definition at line 442 of file GThreads.h.
int GThread::yield | ( | ) | [inline, static] |
Causes the current thread to relinquish the processor.
The scheduler selects a thread ready to run and transfers control to that thread. The actual effect of yield# heavily depends on the selected implementation. Function yield# usually returns zero when the execution of the current thread is resumed. It may return a positive number when it can determine that the current thread will remain the only runnable thread for some time. You may then call function {get_select} to obtain more information.
Definition at line 443 of file GThreads.h.
Member Data Documentation
void* GThread::xarg |
Definition at line 330 of file GThreads.h.
void(* GThread::xentry)(void *) |
The documentation for this class was generated from the following files: