我有一个应用程序,我有两个操作读写,两个操作将同时发生,所以我使用的同步技术 [英] I have an application there , I have two operations read and write and two operation will be occured simultaneously so which synchronization technique I use

查看:128
本文介绍了我有一个应用程序,我有两个操作读写,两个操作将同时发生,所以我使用的同步技术的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序有一个任务但是在这个任务中有两个操作,一个操作是从文本文件读取另一个是写入另一个文本文件和所有数据来自另一个引擎。所以数据来得非常高速度所以我必须使用多线程来完成我的工作。因为如果它是连续完成数据丢失将发生。所以我的问题是我使用哪种同步技术完成我的工作。请帮助我并给出一些伪代码或链接我能理解做我的工作。请帮忙,我等你的回复............



[更新18-2-13 ]

请给出一些代码示例....

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

推荐答案

基本上,因为这是一个应用程序,一个进程,你可以使用最轻量级的互斥:关键部分对象:

http:/ /en.wikipedia.org/wiki/Critical_section [ ^ ],

http://msdn.microsoft.com/en-us/library/windows/desktop/ms682530%28v=vs.85%29.aspx [ ^ ]。



对于某些背景,请参阅: http://en.wikipedia.org/wiki/Mutual_exclusion [ ^ ]。



但是,由于问题非常模糊,这不能最终答案,这就是大多数在大多数情况下,可能会对你有用。您应该始终记住最佳同步不同步。在不需要同步的情况下有很多种情况。例如,当您的读取或写入操作通过某种消息传递机制时,它们已经被序列化。但是,当您将读取结果应用于影响应用程序状态的某个共享对象时,您需要对执行更新和获取此状态的代码执行互斥。进一步的分析需要进一步的细节。



-SA
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


我是<的粉丝a href =http://www.codeproject.com/Articles/481168/Using-the-Actor-Programming-Model>演员编程模型 [ ^ ],它封装了所有同步细节,因此您不需要这样做你自己。编写从actor对象派生的reader和writer类,并且对象之间的所有活动都将被正确地线程化并且访问同步。数据传输通过消息传递机制(在解决方案#1中提到)正确地序列化和同步。
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.


这篇关于我有一个应用程序,我有两个操作读写,两个操作将同时发生,所以我使用的同步技术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆