Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MFC VC++
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 17-Feb-13 9:36am
debarunb1.1K
Edited 17-Feb-13 19:03pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 406
1 Marcin Kozub 225
2 Sergey Alexandrovich Kryukov 205
3 /\jmot 175
4 Shweta N Mishra 161
0 OriginalGriff 8,289
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,624
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 18 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100