DCMTK Version 3.6.8
OFFIS DICOM Toolkit
|
provides an operating system independent abstraction for threads. More...
Public Member Functions | |
OFThread () | |
default constructor. More... | |
virtual | ~OFThread () |
destructor. More... | |
int | start () |
adds a new thread of control to the current process. More... | |
int | join () |
blocks the calling thread until the thread referenced by the OFThread object terminates. More... | |
unsigned long | threadID () |
returns the thread identifier of the thread referenced by the OFThread object, if the thread has already been started. More... | |
OFBool | equal (unsigned long tID) |
checks if the given thread ID matches the thread ID of the thread referenced by this object. More... | |
Static Public Member Functions | |
static void | errorstr (OFString &description, int code) |
converts any of the error codes returned by the methods of this class into a textual description, which is written into the string object. More... | |
Static Public Attributes | |
static const int | busy |
this constant is returned by the join() method if another thread is already waiting for termination of the thread referenced by the OFThread object. More... | |
Static Protected Member Functions | |
static void | thread_exit () |
terminates the calling thread, in a similar way that exit() terminates the calling process. More... | |
static unsigned long | self () |
returns the thread ID of the calling thread. More... | |
Private Member Functions | |
virtual void | run ()=0 |
this method implements the thread that is run by calling the start method of the OFThread object. More... | |
OFThread (const OFThread &arg) | |
unimplemented private copy constructor | |
OFThread & | operator= (const OFThread &arg) |
unimplemented private assignment operator | |
Private Attributes | |
unsigned long | theThread |
thread identifier | |
Friends | |
DCMTK_OFSTD_EXPORT void * | thread_stub (void *arg) |
thread stub must be friend to call run() More... | |
provides an operating system independent abstraction for threads.
Threads are executed asynchronously in parallel to the main thread of the process. On multi-processor machines threads may run on different CPUs if the operating system permits. This class is abstract. Deriving classes must implement the run() method which contains the code executed by the thread.
OFThread::OFThread | ( | ) |
|
virtual |
destructor.
Destruction of an OFThread object does not cause the referenced thread to be stopped and may result in undefined behaviour if the derived class maintains thread specific data in this object (which is not recommended). The join() method should be called prior to destruction of the thread object to make sure a thread has terminated.
OFBool OFThread::equal | ( | unsigned long | tID | ) |
checks if the given thread ID matches the thread ID of the thread referenced by this object.
tID | thread ID to be compared |
|
static |
converts any of the error codes returned by the methods of this class into a textual description, which is written into the string object.
description | string object into which the error description is written. |
code | error code |
int OFThread::join | ( | ) |
blocks the calling thread until the thread referenced by the OFThread object terminates.
Several threads cannot wait for the same thread to complete; one thread will complete the join() method successfully others may or may not return OFThread::busy. The method will not block the calling thread if the target thread has already terminated.
|
privatepure virtual |
this method implements the thread that is run by calling the start method of the OFThread object.
Defined as abstract method in OFThread. It is recommended that derived classes implementing this method do not rely on attributes of the OFThread object because this might result in undefined behaviour if another thread deletes or restarts the OFThread object before the thread has terminated.
Implemented in DcmBaseSCPPool::DcmBaseSCPWorker.
|
staticprotected |
returns the thread ID of the calling thread.
For a running thread, this->threadID() and this->self() should return the same value, but self() is more robust and should be preferred. On certain platforms like OSF/1, a thread ID contains a pointer to a structure. Therefore, thread IDs should never be compared directly, but always using the equal() method provided in this class.
int OFThread::start | ( | ) |
adds a new thread of control to the current process.
The main() procedure itself is a single thread of control. Each thread executes simultaneously with all the other threads within the calling process. A newly created thread shares all of the calling process' global data with the other threads in this process except the execution stack. The new thread executes the run() method and terminates upon return from this method or a call to thread_exit() from within the thread. This method should not be called if a thread is already running, otherwise a new thread will be started and the identifier of the old thread will be overwritten, making it impossible to call join() for the old thread. It may also result in undefined behaviour if the derived class maintains thread specific data in this object (which is not recommended).
|
staticprotected |
terminates the calling thread, in a similar way that exit() terminates the calling process.
This method does not return.
unsigned long OFThread::threadID | ( | ) |
returns the thread identifier of the thread referenced by the OFThread object, if the thread has already been started.
Otherwise returns 0. On certain platforms like OSF/1, a thread ID contains a pointer to a structure. Therefore, thread IDs should never be compared directly, but always using the equal() method provided in this class.
|
friend |
|
static |