473,698 Members | 2,261 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 4412

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
2071
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
2847
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
3051
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
2053
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
8609
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9169
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
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7738
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...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4371
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
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2335
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
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.