![]() |
Main Page
Class Hierarchy
Alphabetical List
Compound List
File List
Compound Members
![]() |
#include <FXThread.h>
Inheritance diagram for FXEX::FXThread::
The idea here is that you derive from this class, to create your wroker thread. Facilities are provided to: a) start the thread, from another thread b) request a stop from another thread.
Note, the stop functionality only provides a facility to 'request' a stop of a thread. There isn't an implementation that I can think of (in a working program) where forcibly stopping a thread is a good thing... As such, it is up to the worker thread to periodically poll the status of the 'stopThread' variable, to find out if another thread (ie the main thread) has asked the worker thread to stop. This is reasonably important, since the owner thread will wait for the worker thread to stop before it will completely destruct.
Your derived class only need to implement the 'run()' method. This method is started in a worker thread when you call start() on the object. If you need to pass parameters to the worker thread, just create set/get methods in your derived class (which then sets/gets the parameter that you want access to).
To facilitate simple access to class local variables, the FXThread class inherits a mutex (call 'mutex') from the FXRunnable class. Your accessor methods then simply needs to either: a) call lock()/unlock() on the mutex b) use the FXSynchronise object to auto-lock/unlock the mutex
Alternatively you could use the FXAtomic data types, which provide implicit lock/unlock calls for each of its accessor methods. This technique is used internally within the FXAtomicDataTarget class to create a FOX DataTarget which works across threads.
Definition at line 61 of file FXThread.h.