CIBC:Documentation:SCIRun:DevTasks:QtMigration:BoostThread
Contents
- 1 Boost Thread notes
- 1.1 AtomicCounter
- 1.2 Barrier
- 1.3 CleanupManager
- 1.4 ConditionVariable
- 1.5 CrowdMonitor
- 1.6 FutureValue
- 1.7 Guard
- 1.8 Mailbox
- 1.9 Mutex
- 1.10 MutexPool
- 1.11 Parallel
- 1.12 ParallelBase
- 1.13 RecursiveMutex
- 1.14 Reducer
- 1.15 Runnable
- 1.16 Semaphore
- 1.17 SimpleReducer
- 1.18 Thread
- 1.19 ThreadError
- 1.20 ThreadGroup
- 1.21 ThreadLock
- 1.22 ThreadPool
- 1.23 Time
- 1.24 UsedWithLockingHandle
- 1.25 WorkQueue
Boost Thread notes
Working from Boost 1.49.
These are notes for replacing Core/Thread with Boost threads.
AtomicCounter
In Core/Thread/AtomicCounter.h. See atomic_count.hpp.
Most important use is in Datatype as generation counter.
Mapping
- operator int() =
- allows the atomic counter to be used in expressions like a normal integer (note that multiple calls to this function may return different values if other threads are manipulating the counter)
- operator++() =
- 2 versions
- operator--() =
- 2 versions
- set(int) =
- set to new value
- used in Module.cc to update ProgressReporter progress - we could use signals/slots to make this obsolete
Barrier
In Core/Thread/Barrier.h. See barrier.hpp.
Mapping
- wait() = boost::barrier::wait()
- set number of threads in barrier constructor instead of arg to boost::barrier::wait()
CleanupManager
Mapping
ConditionVariable
Mapping
CrowdMonitor
In Core/Thread/CrowdMonitor.h. This is a multiple reader, single writer synchronization primitive.
Boost's shared_lock looks like it could be a substitute for the multiple reader functionality, and unique_lock could be a substitute for single writer. See also http://lists.boost.org/Archives/boost/2008/01/132656.php.
Mapping
- readLock() =
- readUnlock() =
- writeLock() =
- writeUnlock() =
FutureValue
Mapping
Guard
In Core/Thread/Guard.h. See Boost lock types. Used extensively.
Mapping
- constructors that take Mutex, RecursiveMutex, CrowdMonitor
- Guard is mostly used with Mutex
- CrowdMonitor is not used with Guard
Mailbox
Mapping
Mutex
Mapping
MutexPool
Mapping
Parallel
Parallel1
Parallel2
Parallel3
Parallel4
Mapping
ParallelBase
Mapping
RecursiveMutex
In Core/Thread/RecursiveMutex.h. See recursive_mutex.
Mapping
- lock() = boost::recursive_mutex::lock()
- tryLock() = boost::recursive_mutex::try_lock()
- unlock() = boost::recursive_mutex::unlock()
Reducer
Mapping
Runnable
Mapping
Semaphore
Mapping
SimpleReducer
Mapping
Thread
Mapping
- getThreadGroup() =
- not used
- getRunnable() =
- not used
- setDaemon() =
- used in ThreadPool and main.cc for Scheduler thread, but with redesign, it is unlikely that we will need this feature
- isDaemon() =
- not used outside of Core/Thread library
- activate() =
- change Thread state from inactive to active
- not supported by boost::thread class
- used in Dataflow/Modules/Render/OpenGL.cc - not sure why it's needed there, since helper Thread is instantiated as inactive and then activated right away...call to yield() seems more important
- detach() =
- isDetached() =
- setStackSize() =
- getStackSize() =
- exitAll() =
- used in TCLThread and NetworkEditor on exit
- exit() =
- self() =
- stop() =
- resume() =
- not used outside of Core/Thread library
- join =
- getThreadName() =
- numProcessors() = boost::thread::hardware_concurrency()
- used frequently
- migrate(int proc) =
- not used outside of Core/Thread library
- parallel() = custom implementation needed
- used frequently
- starts up several threads that run in parallel
- multiple overloaded versions
- Seg3D2 has an implementation
- niceAbort() =
- let's find a better way to fail the program gracefully (with logging too)
- couldBlock() =
- not used outside of Core/Thread library
- used in AtomicCounter, Barrier, CrowdMonitor default implementations
- also used in Mailbox, SimpleReducer, FutureValue
- couldBlockDone() =
- not used outside of Core/Thread library
- yield() = boost::thread::yield
- isInitialized() =
- not used outside of Core/Thread library
- setDefaultAbortMode() =
- not used
- initialize() =
ThreadError
Mapping
ThreadGroup
In Core/Thread/ThreadGroup.h.
See the threadgroup class. I don't think thread_group supports daemon threads.
ThreadGroup is not used outside of the Core/Thread library
Mapping
- numActive() = boost::thread_group::size()
- not used
- stop() =
- resume() =
- join() =
- detach() =
- parentGroup() =
- not used
- gangSchedule() =
- not used
ThreadLock
Mapping
ThreadPool
In Core/Thread/ThreadPool.h.
ThreadPool is not used outside of the Core/Thread library
Mapping
Time
In Core/Thread/Time.h.
See also [[1]].
Mapping
- currentTicks() =
- currentSeconds() =
- ticksPerSecond() =
- secondsPerTick() =
- waitUntil(SysClock ticks) =
- wait until the specified time
- overloaded for long long (system clock ticks), double (seconds)
- waitFor(SysClock ticks) =
- wait for the specified time
- overloaded for long long (system clock ticks), double (seconds)
UsedWithLockingHandle
In Core/Thread/UsedWithLockingHandle.h.
Wrapper for SCIRun LockingHandle smart pointer type. If still needed, change mutex class types.