![]() |
Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
|
FXThread provides system-independent support for threads. More...
#include <FXThread.h>
Public Types | |
| enum | Priority { PriorityError = -1, PriorityDefault, PriorityMinimum, PriorityLower, PriorityMedium, PriorityHigher, PriorityMaximum } |
| Thread priority levels. More... | |
| enum | Policy { PolicyError = -1, PolicyDefault, PolicyFifo, PolicyRoundRobin } |
| Thread scheduling policies. More... | |
Public Member Functions | |
| FXThread () | |
| Initialize thread object. | |
| FXThreadID | id () const |
| Return handle of this thread object. | |
| FXbool | running () const |
| Return true if this thread is running. | |
| FXbool | start (unsigned long stacksize=0) |
| Start thread; the thread is started as attached. | |
| FXbool | join () |
| Suspend calling thread until thread is done. | |
| FXbool | join (FXint &code) |
| Suspend calling thread until thread is done, and set code to the return value of run() or the argument passed into exit(). | |
| FXbool | cancel () |
| Cancel the thread, stopping it immediately, running or not. | |
| FXbool | detach () |
| Detach thread, so that a no join() is necessary to harvest the resources of this thread. | |
| FXbool | priority (Priority prio) |
| Set thread scheduling priority. | |
| Priority | priority () const |
| Return thread scheduling priority. | |
| FXbool | policy (Policy plcy) |
| Set thread scheduling policy. | |
| Policy | policy () const |
| Get thread scheduling policy. | |
| FXbool | affinity (FXulong mask) |
| Change thread's processor affinity, the set of processors onto which the thread may be scheduled. | |
| FXulong | affinity () const |
| Get thread's processor affinity. | |
| FXbool | suspend () |
| Suspend thread; return true if success. | |
| FXbool | resume () |
| Resume thread; return true if success. | |
| virtual | ~FXThread () |
| Destroy the thread immediately, running or not. | |
Static Public Member Functions | |
| static void | exit (FXint code=0) |
| Exit the calling thread. | |
| static void | yield () |
| Make the thread yield its time quantum. | |
| static FXTime | time () |
| Return time in nanoseconds since Epoch (Jan 1, 1970). | |
| static void | sleep (FXTime nsec) |
| Make the calling thread sleep for a number of nanoseconds. | |
| static void | wakeat (FXTime nsec) |
| Wake at appointed time specified in nanoseconds since Epoch. | |
| static FXThread * | self () |
| Return pointer to the FXThread instance associated with the calling thread; it returns NULL for the main thread and all threads not created by FOX. | |
| static FXThreadID | current () |
| Return thread id of calling thread. | |
| static FXint | processors () |
| Return number of available processors (cores) in the system. | |
| static FXThreadStorageKey | createStorageKey () |
| Generate new thread local storage key. | |
| static void | deleteStorageKey (FXThreadStorageKey key) |
| Dispose of thread local storage key. | |
| static void * | getStorage (FXThreadStorageKey key) |
| Get thread local storage pointer using key. | |
| static void | setStorage (FXThreadStorageKey key, void *ptr) |
| Set thread local storage pointer using key. | |
Static Protected Member Functions | |
| static void | self (FXThread *t) |
FXThread provides system-independent support for threads.
Subclasses of FXThread must implement the run() function to implement the desired functionality of the thread object. The thread can be started by calling start(), passing an optional size to allocate for the thread's stack space. Each thread can have thread-local storage. FXThread has at least one thread-local variable, a pointer to the FXThread object itself; this value can be obtained at any time during the execution of the thread by calling self(). The value of self() is automatically set when the thread is started. Additional thread-local variables may be obtained using FXAutoThreadStorageKey. Initially, all signals are masked by newly started threads (only the main thread will normally handle signals). To reclaim the resources once the thread is completed, a call to join() must be made, or the thread must be detached (note however that detaching the thread will sever the association between FXThread and the thread). Exceptions thrown from within the execution of the thread are caught, and cause a return value of -1. Calling the destructor from within the thread itself (suicide) is allowed; the thread will be detached and terminate immediately. Calling the destructor from another thread will cancel() the thread if it is still running. Due to the asynchronous nature of threads, it is usually not a good idea to do this; it is recommended that subclasses call join(), and delay the execution of the destructor until the thread has completed normally.
| enum FX::FXThread::Policy |
Thread priority levels.
| virtual FX::FXThread::~FXThread | ( | ) | [virtual] |
Destroy the thread immediately, running or not.
It is probably better to wait until it is finished, in case the thread currently holds mutexes.
| FXbool FX::FXThread::cancel | ( | ) |
Cancel the thread, stopping it immediately, running or not.
If the calling thread is this thread, nothing happens. It is probably better to wait until it is finished, in case the thread currently holds mutexes. The FXThreadID is reset back to zero after the thread has been stopped.
| FXbool FX::FXThread::detach | ( | ) |
Detach thread, so that a no join() is necessary to harvest the resources of this thread.
The thread continues to run until normal completion.
| static void FX::FXThread::exit | ( | FXint | code = 0 | ) | [static] |
Exit the calling thread.
No destructors are invoked for objects on thread's stack; to invoke destructors, throw an exception instead.
| FXThreadID FX::FXThread::id | ( | ) | const |
Return handle of this thread object.
This handle is valid in the context of the thread which called start().
| FXbool FX::FXThread::join | ( | ) |
Suspend calling thread until thread is done.
The FXThreadID is reset back to zero.
| FXbool FX::FXThread::join | ( | FXint & | code | ) |
| FXbool FX::FXThread::start | ( | unsigned long | stacksize = 0 | ) |
Start thread; the thread is started as attached.
The thread is given stacksize for its stack; a value of zero for stacksize will give it the default stack size. This invokes the run() function in the context of the new thread.
|
|