ASL
|
The Thread class represents an execution thread.
To create threads, derive a class from Thread and reimplement the run()
function. That is what objects of the new class will execute in parallel when the start()
function is called.
In compilers supporting lambdas threads can now be started with a lambda without defining a specific Thread subclass. These threads can get input data or keep state using variables captured by the lambda.
#include <Thread.h>
Public Member Functions | |
virtual void | run () |
The thread procedure. More... | |
void | start () |
Starts a new thread by calling run() in parallel. | |
void | kill () |
Cancels a thread, but you should not normally do this. More... | |
void | join () |
Waits for this thread to end. | |
bool | finished () const |
Returns true if this thread has finished. | |
template<class F > | |
Thread (const F &f) | |
Starts a thread given a function or lambda expression as the run() function. | |
Static Public Member Functions | |
static int | numProcessors () |
Returns the number of logical processors or cores. | |
template<class F > | |
static void | parallel_for (int i0, int i1, const F &f, int nth=8) |
Emulates an OpenMP parallel for by running function f several times in parallel. More... | |
template<class F1 , class F2 > | |
static void | parallel_invoke (const F1 &f1, const F2 &f2) |
Runs the two functions/lambdas in parallel and returns when both are finished. | |
template<class F1 , class F2 , class F3 > | |
static void | parallel_invoke (const F1 &f1, const F2 &f2, const F3 &f3) |
Runs the 3 functions/lambdas in parallel and returns when all are finished. | |
template<class F1 , class F2 , class F3 , class F4 > | |
static void | parallel_invoke (const F1 &f1, const F2 &f2, const F3 &f3, const F4 &f4) |
Runs the 4 functions/lambdas in parallel and returns when all are finished. | |
|
inline |
Cancels a thread, but you should not normally do this.
|
inlinestatic |
Emulates an OpenMP parallel for by running function f
several times in parallel.
Function f
must receive an integer argument which will get the values from i0
up to but not including i1
.
Is equivalent to running:
but with iterations run in nth
parallel threads.
|
inlinevirtual |
The thread procedure.
Reimplement this function to create new threads