boss-worker model in C++

J

John

Is there a good implementation of the boss-worker model
in C++ using pthreads? I have an array of objects A that each
need processing and I have p threads running simultaneosly.
Any object can be processed by any thread. All objects need
to get processed.

Does anyone know of a good design/implementation of this problem
in C++?

Thanks a lot for your help,
--j


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
M

Maxim Yegorushkin

John said:
Is there a good implementation of the boss-worker model
in C++ using pthreads? I have an array of objects A that each
need processing and I have p threads running simultaneosly.
Any object can be processed by any thread. All objects need
to get processed.

Does anyone know of a good design/implementation of this problem
in C++?

You can take an atomic queue from
http://groups.google.com/group/comp.lang.c++.moderated/msg/48b7b7569f04d181
Make the boss thread post jobs (functors) using atomic_queue::push(),
all the worker threads call atomic_queue::pop() and then execute the
job received so.

It uses boost.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
S

Stefan Arentz

John said:
Is there a good implementation of the boss-worker model
in C++ using pthreads? I have an array of objects A that each
need processing and I have p threads running simultaneosly.
Any object can be processed by any thread. All objects need
to get processed.

Does anyone know of a good design/implementation of this problem
in C++?

I got my copy of http://java.sun.com/docs/books/cp/ and implemented
many patterns in a nice C++ manner. Even though it is Java centric,
the book is really excellent as it touches many concurrency issues.

S.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
K

kanze

John said:
Is there a good implementation of the boss-worker model in C++
using pthreads? I have an array of objects A that each need
processing and I have p threads running simultaneosly. Any
object can be processed by any thread. All objects need to get
processed.
Does anyone know of a good design/implementation of this
problem in C++?

Wouldn't the usual consumer/producer pattern work? The boss
thread posts requests in a message queue; the worker threads
wait on the message queue, and process requests the extract from
it. In this case, the "request" could be as simple as an int,
the index into the array.

--
James Kanze GABI Software
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,158
Latest member
Vinay_Kumar Nevatia
Top