Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members

FXEX::FXThreadFunction Class Reference

You can start a worker thread for running your task. More...

#include <FXThreadFunction.h>

Inheritance diagram for FXEX::FXThreadFunction::

FXEX::FXRunnable FXEX::FXThreadedObject FXObject List of all members.

Detailed Description

You can start a worker thread for running your task.

It runs with a lower priority than your main thread. It runs as a detached thread (ie you main thread cant/shouldn't wait for it to finish). example:

// declare file scope pointer to variable FXThreadFunction *thread; // declare some variables...

// do some work void workerFunction(){ while (...) { // use global variables, including some atomic's ... if (..) thread->signal(); ... } }

// FOX message map - handle a thread event ... FXMAPFUNC(SEL_CREATE,MyApp::ID_WORKER,MyApp:onWorker), FXMAPFUNC(SEL_THREAD,MyApp::ID_WORKER,MyApp:onWorker), FXMAPFUNC(SEL_DESTROY,MyApp::ID_WORKER,MyApp:onWorker), ...

// main window/thread MyApp::MyApp(a):FXMainWindow(a){ ... // setup variables ... // create the thread thread = new FXThreadFunction(workerFunction,this,ID_WORKER); ... }

MyApp::create(){ thread->start(); }

// handle thread event long MyApp::onWorker(,,){ // update something // reset variables return 1; }

alternatively:

FXAtomicInt atomicInt;

MyApp::MyApp(a):FXMainWindow(a){ ... atomicInt=0; atomicIntDataTarget.connect(atomicInt); thread = new FXThreadFunction(workerFunction,...); ... new FXTextField(this,10,atomicIntDataTarget,FXDataTarget::ID_VALUE,...); ... }

void MyApp::workerFunction(){ while (...) { // do some work ... atomicInt++; } }

Definition at line 104 of file FXThreadFunction.h.