HDK
|
#include <UT_ThreadedAlgorithm.h>
Public Member Functions | |
UT_ThreadedAlgorithm (int maxthreads=-1) | |
~UT_ThreadedAlgorithm () | |
UT_ThreadedAlgorithm (const UT_ThreadedAlgorithm &)=delete | |
UT_ThreadedAlgorithm & | operator= (const UT_ThreadedAlgorithm &)=delete |
void | run (void(*threadfunc)(void *, int, int, UT_Lock &), void *userdata, UT_Lock *lock=0) |
void | run (UT_Functor1< int, const UT_JobInfo & > functor, UT_Lock *lock=0) |
UT_ThreadedAlgorithm takes care of all the thread administration that a threaded algorithm requires.
NOTE: UT_ParallelUtil is the modern preferred method of multithreading and should usually be used for new code.
Its features are: 1) it executes work in the main thread as well 2) it assumes that the work can be divided into N parts and sends off exactly N calls to threadfunc() (jobs). (N depends on the # of installed processors and the maxthreads parm).
Your callback function is called with several useful parameters:
void * data - the userdata pointer you provide to run() int jobindex - there are N jobs, this is which job you're running (0 to N-1). int maxindex - the total number of jobs farmed (N) UT_Lock &lock - a lock that you can use to lock other jobs out while you work on something non-threadsafe. Accepts NULL.
If your machine is a single proc, this will work exactly as a call to threadfunc().
In addition to the traditional threadfunc() callback, you can pass in a UT_Functor1 which takes a UT_JobInfo parameter to specify the job to be performed (see below). In this case, you may be better off with the THREADED_METHOD macros detailed later.
Definition at line 57 of file UT_ThreadedAlgorithm.h.
UT_ThreadedAlgorithm::UT_ThreadedAlgorithm | ( | int | maxthreads = -1 | ) |
UT_ThreadedAlgorithm::~UT_ThreadedAlgorithm | ( | ) |
|
delete |
|
delete |
void UT_ThreadedAlgorithm::run | ( | void(*)(void *, int, int, UT_Lock &) | threadfunc, |
void * | userdata, | ||
UT_Lock * | lock = 0 |
||
) |
Starts the jobs, and waits until all are finished. This can be called multiple times. The optional lock parm allows you to use your own lock; if not specified, this class's lock will be used.
void UT_ThreadedAlgorithm::run | ( | UT_Functor1< int, const UT_JobInfo & > | functor, |
UT_Lock * | lock = 0 |
||
) |
Starts the jobs and waits until all are finished. Since this uses a functor, you are expected to use BindFirst to hide any user data you may have While a return type is specified, it is not used. This is because compiler bugs prohibit a Functor2 that returns null.