Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,
I am new to parallel programming so I do not know how should I actually go to implement this,
My requirement is that I have to develop an application in which two things would be done simultaneously, First task is to listen the values from source and once total count of read values become 100 pass those collected values to another process that would save those values to database and at the same time first process will continue listening and passing those value to second process once count reached to 100 and process continue.

Thanks in advance
Posted

1 solution

This is a big topic, so I'll tell you only about the most important aspects.

First of all, please see: http://msdn.microsoft.com/en-us/library/c5kehkcz.aspx[^].

See also: http://en.wikipedia.org/wiki/Mutual_exclusion[^].

You should also clearly understand such things as:
http://en.wikipedia.org/wiki/Race_condition[^],
http://en.wikipedia.org/wiki/Deadlock[^].

But it your case, it looks like you need more high-level mechanism. Please see my article:
Simple Blocking Queue for Thread Communication and Inter-thread Invocation[^].

See also my past answers on the thread wrapper, in the part of synchronization:
How to pass ref parameter to the thread[^],
Change parameters of thread (producer) after it is started[^],
MultiThreading in C#[^].

I would love to write a whole book on the topic, but this is a Quick Questions & Answers forum. :-)

—SA
 
Share this answer
 
Comments
MK-Gii 2-Oct-13 3:35am    
Excellent answer. I would add the following link:
http://msdn.microsoft.com/en-us/library/aa645740(v=vs.71).aspx
This a bunch of good examples - one will be very close to the defined situation.
Sergey Alexandrovich Kryukov 2-Oct-13 4:11am    
Thank you, Modestas.

You could put it as a useful answer, too. However, it would not be complete: as I can see, OP needs something like a communication via a blocking queue.

—SA
MK-Gii 2-Oct-13 4:27am    
Yeah.. you're right... when I read the question again I noticed that 2 way sygnaling might not be all what meets the eye here. And the links you gave are worth for my own attention too. Thanks for that!
Sergey Alexandrovich Kryukov 2-Oct-13 11:29am    
You are welcome.
—SA
Joezer BH 2-Oct-13 8:09am    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900