OpendTect
6.6
|
interface to threads that should be portable. More...
Classes | |
class | Atomic |
class | AtomicPointer |
Atomic instantiated with a pointer. The class really only handles the casting from a void* to a T*. More... | |
class | Barrier |
Waits for a number of threads to reach a certain point (i.e. the call to Barrier::waitForAll). Once everyone has arrived, everyone is released. More... | |
class | ConditionVar |
Is an object that faciliates many threads to wait for something to happen. More... | |
class | Lock |
A lock of a type that (hopefully) suits your needs. To use it, you need the Locker class. More... | |
class | Locker |
Locks the lock, shutting out access from other threads if needed. More... | |
class | Mutex |
Is a lock that allows a thread to have exlusive rights to something. More... | |
class | MutexLocker |
class | ReadLockLocker |
class | ReadWriteLock |
Lock that permits multiple readers to lock the object at the same time, but it will not allow any readers when writelocked, and no writelock is allowed when readlocked. More... | |
class | SpinLock |
Is an alternative to Mutex. It is a lock which causes a thread trying to acquire it to simply wait in a loop ("spin") while repeatedly checking if the lock is available. Because they avoid overhead from operating system process re-scheduling or context switching, spinlocks are efficient if threads are only likely to be blocked for a short period. More... | |
class | SpinRWLock |
Is an alternative to ReadWriteLock. It is a lock which causes a thread trying to acquire it to simply wait in a loop ("spin") while repeatedly checking if the lock is available. Because they avoid overhead from operating system process re-scheduling or context switching, spinlocks are efficient if threads are only likely to be blocked for a short period. More... | |
class | Thread |
Is the base class for all threads. Start it by creating it and give it the function or CallBack to execute. More... | |
class | Work |
The abstraction of something that can be done. It can be an ordinary CallBack, a static function (must return bool) or a TaskFunction on a CallBackerinheriting class, or a Task. The three examples are shown below. More... | |
class | WorkManager |
Takes work and puts it on a queue for execution either in parallel, singlethread or manual. More... | |
class | WriteLockLocker |
Typedefs | |
typedef void * | ThreadID |
Functions | |
bool | atomicSetIfValueIs (volatile int &val, int curval, int newval, int *actualvalptr) |
ThreadID | currentThread () |
int | getNrProcessors () |
int | getSystemNrProcessors () |
bool | lockSimpleSpinLock (volatile int &lock, Locker::WaitType) |
bool | lockSimpleSpinWaitLock (volatile int &lock) |
void | setCurrentThreadProcessorAffinity (int cpu) |
void | sleep (double seconds) |
void | unlockSimpleSpinLock (volatile int &lock) |
interface to threads that should be portable.
simple interface to thread locking
As usual, other thread systems are available but they are as far as we know simply too big and dependent.
The two ingredients are: The lock itself - commonly a class variable A locker (managing the setting and releasing of the lock)
Typical usage:
class X { ... Threads::Lock datalock_; ... };
void X::doSomething() { Threads::Locker locker( datalock_ ); for ( int i..... }
typedef void* Threads::ThreadID |
bool Threads::atomicSetIfValueIs | ( | volatile int & | val, |
int | curval, | ||
int | newval, | ||
int * | actualvalptr | ||
) |
Atomically sets the 'val' only if its value is currently the value of 'curval'. If the value in 'val' is identical to the value of 'curval', function will change 'val' and return true. Otherwise, it will not change 'val', it will return false, and update the value at 'actualvalptr' to the current value of 'val'.
ThreadID Threads::currentThread | ( | ) |
int Threads::getNrProcessors | ( | ) |
int Threads::getSystemNrProcessors | ( | ) |
Fetches number of processors from operating system, unless: DTECT_USE_MULTIPROC is set to 'n' or 'N' The user settings contain a 'Nr Processors' entry.
bool Threads::lockSimpleSpinLock | ( | volatile int & | lock, |
Locker::WaitType | |||
) |
bool Threads::lockSimpleSpinWaitLock | ( | volatile int & | lock | ) |
Any volatile integer that is initialized to 0 can act as a spinlock using this funciton. If you lock it, you have to unlock it by setting it to 0. Note that parallelStudio will report these as violations of thread-safety. Hence use thes only when standard locks cannot be used (e.g. static locks in functions).
void Threads::setCurrentThreadProcessorAffinity | ( | int | cpu | ) |
Tells the current thread to always run on a certain cpu. Set to -1 to remove binding. Not guaranteed to work on all platforms.
void Threads::sleep | ( | double | seconds | ) |
Causes the current thread to sleep
void Threads::unlockSimpleSpinLock | ( | volatile int & | lock | ) |
Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B.V. 1995-2022