Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an application there is a one task but in this task there is two operation one operation is reading from text file an another is write to another text file and all the data com from another engine.So data is coming very high speed so I have to used multi threading to do my job.Because if it is serially done data loss will happens.So my question is which synchronization technique I use to my Job done.Please help me and give some pseudo code or link that I can understand do my work.Please help,I am waiting for your reply............

[Updated 18-2-13]
Give some code example please....
Posted
Updated 17-Feb-13 18:03pm
v2

Basically, as this is one application, one process, you can use the most light weight form of mutual exclusion: critical section object:
http://en.wikipedia.org/wiki/Critical_section[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682530%28v=vs.85%29.aspx[^].

For some background, please see also: http://en.wikipedia.org/wiki/Mutual_exclusion[^].

However, as the question is very vague, this cannot be a final answer, this is what most likely will work for you in most cases. You should always remember that best synchronization is no synchronization. There are many scenarios when synchronization is not needed. For example, when your read or write operations go through some messaging mechanism, they are already serialized. But when you apply the read results to some shared object which affect your application state, you need to perform mutual exclusion on the code which performs the update and acquisition of this state. Further analysis would require further detail.

—SA
 
Share this answer
 
I am a fan of the Actor Programming Model[^] which encapsulates all the synchronization details so you don't need to do this yourself. Write a reader and writer classes that derive from the actor object and all activities between the objects will be properly threaded and accesses synchronized. The data transfers via a messaging mechanism, which (as touched on in solution #1) is properly serialized and synchronized.
 
Share this answer
 

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