Click here to Skip to main content
11,935,066 members (55,173 online)
Rate this:
Please Sign up or sign in to vote.
See more: MFC VisualC++
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
Edited 17-Feb-13 19:03pm
Rate this: bad
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:[^],[^].

For some background, please see also:[^].

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.

Rate this: bad
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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151126.1 | Last Updated 18 Feb 2013
Copyright © CodeProject, 1999-2015
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