473,698 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need Input from Threading Guru

I'm cursed by being a linear thinker.

Anyway, I have an application (service) where I can't decide on the
appropriate way to implement threading.

I have a timer which periodically initiates Process A
Process A does something, then has to call N instances of Process B, where N
varies from instance to instance of Process A.
Process B then has to call M(n) instances of Process C, for each n < N,
where again the # of instances of Process C varies for each call to process
B.

Clearly, I can do the following: ( process A & B are really in seperate
worker classes, but this is a simplified version)

Main Class

OnTimer( )
{
int N = CalculateNumber OfProcessARequi rements();
for ( int i = 0; i < N; i++) {
Thread t = new Thread( new ThreadStart( this.ProcessA);
t.Start(); }
return;
}

ProcessA()
{
int M = CalculateNumber OfProcessBRequi rements();
for ( int i = 0; i < M; i++) {
Thread t = new Thread( new ThreadStart( This.ProcessB) }
return;
}

ProcessB()
{
DoTheActualWork ();
return;
}

My question is, how do I do the book-keeping.

Nov 16 '05 #1
4 1336
My, that's a lot of threads...

Regardless, it's pretty unclear what you mean by "do the bookkeeping".
Assuming you mean "how do I keep track of the data coming back from all
those DoTheActualWork () calls, my inclination would be to:
1. create an event in the Process B class which the class can raise to
indicate that a DoTheActualWork () call has finished, and has some results to
share. Create an EventArgs-derived class to hold the actual results you
want to pass back to the rest of the program.
2. Have an event handler in the main part of the program to process all the
events arising from those DoTheActualWork () calls.

If you need to keep track of which particular instance of DoTheActualWork ()
was responsible for a given result, then make sure to give all your threads
unique names when your ProcessA() routine creates them. The individual
this.ProcessB() calls can get their own thread name and include that as part
of their results when they pass results back to the rest of the program via
the EventArgs class. If you're clever about how you name your threads,
you'll be able to determine which thread was which when the results come
back.

If you mean something else by "do the bookkeeping", you'll just have to be
more specific...

"Phillip N Rounds" <pr*****@cassan dragroup.com> wrote in message
news:uJ******** ******@TK2MSFTN GP09.phx.gbl...
I'm cursed by being a linear thinker.

Anyway, I have an application (service) where I can't decide on the
appropriate way to implement threading.

I have a timer which periodically initiates Process A
Process A does something, then has to call N instances of Process B, where
N varies from instance to instance of Process A.
Process B then has to call M(n) instances of Process C, for each n < N,
where again the # of instances of Process C varies for each call to
process B.

Clearly, I can do the following: ( process A & B are really in seperate
worker classes, but this is a simplified version)

Main Class

OnTimer( )
{
int N = CalculateNumber OfProcessARequi rements();
for ( int i = 0; i < N; i++) {
Thread t = new Thread( new ThreadStart( this.ProcessA);
t.Start(); }
return;
}

ProcessA()
{
int M = CalculateNumber OfProcessBRequi rements();
for ( int i = 0; i < M; i++) {
Thread t = new Thread( new ThreadStart( This.ProcessB) }
return;
}

ProcessB()
{
DoTheActualWork ();
return;
}

My question is, how do I do the book-keeping.

Nov 16 '05 #2
Phillip N Rounds <pr*****@cassan dragroup.com> wrote:
I'm cursed by being a linear thinker.

Anyway, I have an application (service) where I can't decide on the
appropriate way to implement threading.


I think the best way of thinking about how many threads to have is to
think about how many of your processes could *actually* do work in
parallel (rather than just waiting for access to the CPU, for
instance). I'd then think about using a custom thread pool to create
that many threads (possibly one thread pool per process type) and give
the thread pool jobs from the results of the processes.

I have a custom thread pool you could use here:
http://www.pobox.com/~skeet/csharp/miscutil

and an article about threading which you might find helpful here:
http://www.pobox.com/~skeet/csharp/threads

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
Phillip,

In additon to the others, think about using queue's.

That will as well need threads however probably you can than do better
book-keeping.

Just my thought,

Cor
Nov 16 '05 #4

Sorry all, but I hadn't intended to send this question yet.
As most of you noted, I had to further explain the 'Do the bookeeping'
aspect of the question.
I decided to step back before I posted, based on the possiblity that if
I were to fully explain that portion of the post I might actually come
up with a solution myself.
Thanks for the input and, again, sorry for the poorly worded post.

Phil

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5

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

Similar topics

3
6685
by: Savagesmc | last post by:
Problem Background: I am working on a thin wrapper for the pthreads interface on linux, and have encountered frustrating behavior. The idea is to have a "PosixThread" class that any class can inherit from. A child then only needs to define a virtual "executive" method that has the thread code for the child object, and the threading setup and management are automatic then. The thread creation takes place in the PosixThread base class...
4
9445
by: jas | last post by:
I have a basic client/server socket situation setup....where the server accepts a connection and then waits for commands. On the client side, I create a socket, connect to the server...then I pass the socket to a class which just reads from the socket (in a thread). class Reader(Thread): def run(self): while 1:
6
2426
by: paii | last post by:
I have a table that stores job milestone dates. The 2 milestones I am interested in are "Ship Date" TypeID 1 and "Revised Ship Date" TypeID 18. All jobs have TypeID 1 only some jobs have TypeID 18. I need a query that will return the c date for TypeID 18 if it exist else the date for TypeID 1, for all jobs. the table structure is the following Job TypeID
4
1123
by: Tim::.. | last post by:
I have asked this question several times and can't seem to get the answer I am looking for! I am trying to create a form that responds dynamically to the users choises within the page. At the moment I have a dropdownlist that has the values 1-10 in it. What I want to happen is that when the user selects one of the values... lets say 3! Three parts of the form are repeated! This means that the three parts of the forms input id's have to...
5
3102
by: Sinan Nalkaya | last post by:
hello, i need a function like that, wait 5 seconds: (during wait) do the function but function waits for keyboard input so if you dont enter any it waits forever. i tried time.sleep() but when i used time.sleep in while, the function in while never executed. then i found something about Timer but couldnt realize any algorithm in my mind.
17
2080
by: freemann | last post by:
Can anyone provide example code showing how to send form results to a results page, email and a comma delimited file? Notice that I need it going to all three locations. Details: I have forms created and working. The first form the user fills out and submits. The form properties are set to Send to other: "Custom ISAPI, NSAPI, CGI, OR ASP SCRIPTING. The method is "POST" and the action is "secondpage.asp". I had to go this route because...
24
1895
by: Maric Michaud | last post by:
This is a recurrent problem I encounter when I try to sell python solutions to my customers. I'm aware that this problem is sometimes overlooked, but here is the market's law. I've heard of a bunch of arguments to defend python's choice of GIL, but I'm not quite sure of their technical background, nor what is really important and what is not. These discussions often end in a prudent "python has made a choice among others"... which is not...
7
2374
by: Mike P | last post by:
I am trying to write my first program using threading..basically I am moving messages from an Outlook inbox and want to show the user where the process is up to without having to wait until it has finished. I am trying to follow this example : http://www.codeproject.com/cs/miscctrl/progressdialog.asp But although the messages still get moved, the progress window never does anything. Here is my code in full, if anybody who knows...
3
1449
by: Barkingmadscot | last post by:
I am having problems with Multi-threading and write to Key Access Database I have a log file that and collecting infomation from getting the info is a problem or is writing it the database, the log files a big and it takes time to read down as it get further in to log said, a 100,000 line in I have changed it to mutli-threading which almost works, the problem
0
8612
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
9171
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
9032
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...
1
8905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
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
7743
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
5869
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
4625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.