473,738 Members | 8,848 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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++.m oderated. First time posters: Do this! ]

Feb 21 '06 #1
3 4416

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::p ush(),
all the worker threads call atomic_queue::p op() and then execute the
job received so.

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

Feb 22 '06 #2
"John" <we**********@y ahoo.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++.m oderated. 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 objektorientier ter Datenverarbeitu ng
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++.m oderated. 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
2077
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 wants the development work done in house, and he knows I am in school for a CS minor. I know basic C++(Part 2 of that is in the fall), and I will be taking Java 1 in the fall also. What is the easiest way for me to make windows programs that will do...
7
2852
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 wanting RAC and Data Guard, and is totally anti-UNIX of any kind. He just doesn't take Oracle seriously and he just wants to dump it on any server like an Access DB and ignore it. Today he calls me in and says "forget about RAC and DataGuard --...
18
3056
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 only returning one record. She states that with disctinct the query stops as soon as it finds a matching record. Both of us are relative novices in database theory (obviously). Can someone help settle this?
6
313
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
1158
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 University of Córdoba and in the visit to Altagracia, the city where Che lived in its childhood and together to this to attend immediately the commemoration of the 53 anniversary from the assault to the barracks Moncada and Carlos Manuel of Grasses,...
21
2061
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 kept saying, "I'm afraid to say it's 'OK' to change it because everything I did was for a reason." Well, I know better. My boss' old code is written in some cryptic C file with Oracle precompiler macros barfed all over it. Once I figured out how...
0
8969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9476
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9335
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8210
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2745
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.