相互排斥而不涉及两个过程(Mutual Exclusion Without Touching Both Processes)

系统教程 行业动态 更新时间:2024-06-14 16:57:17
相互排斥而不涉及两个过程(Mutual Exclusion Without Touching Both Processes)

我有一个独特的问题。 尝试访问一个文件有两个进程(P0和P1)。 P0正在向文件写入信息,P1正在读取信息。 在P0完成写入之前P1正在读取的两者之间存在竞争条件。 我考虑过使用Locks,Semaphores等。但是,P1存在于一组代码中,我不允许以任何方式改变它,并且它目前没有实现来支持上面提出的修复。

有没有办法在不触及这两组代码的情况下删除这种竞争条件?

I have a unique problem. There are two processes (P0 and P1) trying to access one file. P0 is writing information to the file and P1 is reading the information. There is a race condition occurring between the two in which P1 is reading before P0 is finished writing. I have considered using Locks, Semaphores, etc. However, P1 exists in a set of code that I am not allowed to alter in any way, and it currently has no implementation to support the above proposed fixes.

Is there any way to remove this race condition without touching both sets of code?

最满意答案

您可以让P0写入文件A并让P1从文件B读取。当P0完成文件写入时,将文件A重命名为文件B.您必须确保重命名操作是原子的。

You can let P0 write to file A and let P1 read from file B. When P0 has completed writing the file, rename file A to file B. You'll have to make sure the rename operation is atomic though.

更多推荐

本文发布于:2023-04-12 20:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/4ac612468e90abd1c8b423594b0a05cf.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:而不   过程   两个   Mutual   Touching

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!