
Hi all, I would like to know how can I do the following: I have n working threads. Each one has a loop preceded by a wait condition (1). When the wait condition is unlocked, the thread takes a task on a queue, and process the task. I need to make something in the submit task function that wait until all processes are on the wait condition (1). How can I do that ? I tried a while(!_nWorking) {} but this is not clean. Here follows my threads function: void ProcessingThread::dispatcher( const int idx ) { using namespace boost; mutex::scoped_lock readyLocker( _dispatchMutex[idx] ); while( !_bDispStop ) { --_nWorking; // Wait for a task _condProcessIn[idx].wait( readyLocker ); ++_nWorking; while( !_bDispStop && !_pendingQueues[idx].empty() ) { _pendingQueuesMutex[idx].lock(); Task task = _pendingQueues[idx].front(); _pendingQueues[idx].pop_front(); _pendingQueuesMutex[idx].unlock(); // Process node assert( task._proc ); assert( task._procData ); task._proc->execute( task._range, *task._procData ); } } } Launched via: _nWorking = _nCpu; for( std::size_t i = 0; i < _nCpu; ++i ) { // Create dispatcher thread _dispThrdGroup.create_thread( boost::bind( &ProcessingThread::dispatcher, this, i ) ); } Submit task function: void ProcessingThread::submitProcess( ProcessLauncher * proc, const FrameRange & range, ProcessData & procData ) { // Get the index of the less used queue std::size_t idx = getLessUsedQueueIdx(); _pendingQueuesMutex[idx].lock(); // Append a task to the less used queue _pendingQueues[ idx ].push_back( Task( proc, range, procData ) ); // Signal that a task is ready _condProcessIn[idx].notify_one(); _pendingQueuesMutex[idx].unlock(); /// UGLY ! while( _nWorking ) { } } Thank you in advance, Eloi Du Bois.

On 11/26/2010 4:48 AM, Eloi Du Bois wrote:
Hi all,
I would like to know how can I do the following:
I have n working threads. Each one has a loop preceded by a wait condition (1). When the wait condition is unlocked, the thread takes a task on a queue, and process the task.
I need to make something in the submit task function that wait until all processes are on the wait condition (1).
I think this is exactly what a 'barrier' does. http://www.boost.org/doc/libs/1_45_0/doc/html/thread/synchronization.html#th...

Excellent ! Thank you very much, that is exactly what I need.
2010/11/26 Eric J. Holtman
On 11/26/2010 4:48 AM, Eloi Du Bois wrote:
Hi all,
I would like to know how can I do the following:
I have n working threads. Each one has a loop preceded by a wait condition (1). When the wait condition is unlocked, the thread takes a task on a queue, and process the task.
I need to make something in the submit task function that wait until all processes are on the wait condition (1).
I think this is exactly what a 'barrier' does.
http://www.boost.org/doc/libs/1_45_0/doc/html/thread/synchronization.html#th... _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Hum... In facts, it is harder than that because I need something like a
barrier with its counter integer that can change dynamically.
For example, a barrier with a function setNum(const int n).
Any idea ?
2010/11/26 Eloi Du Bois
Excellent ! Thank you very much, that is exactly what I need.
2010/11/26 Eric J. Holtman
On 11/26/2010 4:48 AM, Eloi Du Bois wrote:
Hi all,
I would like to know how can I do the following:
I have n working threads. Each one has a loop preceded by a wait condition (1). When the wait condition is unlocked, the thread takes a task on a queue, and process the task.
I need to make something in the submit task function that wait until all processes are on the wait condition (1).
I think this is exactly what a 'barrier' does.
http://www.boost.org/doc/libs/1_45_0/doc/html/thread/synchronization.html#th... _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Eloi Du Bois
-
Eric J. Holtman