473,386 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

boss-worker model in C++

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! ]

Feb 21 '06 #1
3 4380

John wrote:
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....b7b7569f04d181
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! ]

Feb 22 '06 #2
"John" <we**********@yahoo.com> writes:
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! ]

Feb 23 '06 #3
John wrote:
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! ]

Feb 23 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: xeys_00 | last post by:
I'm a manager where I work(one of the cogs in a food service company). The boss needed one of us to become the "tech guy", and part of that is writing small windows programs for the office. He...
7
by: Domenic G. | last post by:
I was wondering how many Oracle DBAs out there have bosses that are complete doe-doe birds? My current boss is a beaut -- has absolutely no concept of Oracle, keeps flipping back and forth from...
18
by: mathilda | last post by:
My boss has been adamant that SELECT DISTINCT is a faster query than SELECT all other factors being equal. I disagree. We are linking an Access front end to a SQL Server back end and normally are...
6
by: Daniel Kaseman | last post by:
I've tried to get my boss to like me, but alas, my efforts proved futile. Help! -Thanks
0
by: gandalf | last post by:
With reason of the enormous effort carried out to visit the Argentinean city of Córdoba, to participate in the Meeting of MERCOSUR, in the closing of the Summit of the Towns in the historical...
21
by: jehugaleahsa | last post by:
Hello: I had an hour-long discussion with my boss today. Last night, right before I dozed off, I realized some of his code resulted in duplicate processing. I tried to explain it to him and he...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.