没有线程的竞争条件?
假设我有: sample.c
int main (...) {
char str*;
get s through user input
test(str);
return 0;
}
void test (str) {
copy str to new file
change file permissions on new file
close file
}
这里不可能出现竞争条件,因为我的 main() 方法中没有线程。这是真的吗?
Let's say I have: sample.c
int main (...) {
char str*;
get s through user input
test(str);
return 0;
}
void test (str) {
copy str to new file
change file permissions on new file
close file
}
There's no possibility of a race condition here since I have no threads in my main() method. Is that true?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
存在一种竞争条件,即用户可以在您更改“新文件”的权限之前立即交换“新文件”。这是(曾经?)经常使用的安全漏洞。
我只是看到尼尔巴特沃斯有一个相关的想法。
There is a kind of race condition in that the user can exchange "new file" immediately before you change permissions of "new file". This is (was?) an often used security exploit.
I just see that Neil Butterworth had a related idea.
存在竞赛的可能性 - 两个用户可以同时运行您的程序。
There is the possibility of a race - two users could run your program at the same time.
竞争条件的另一个来源是中断和信号。如果两者都不使用,则不会发生竞争条件(只有一个赛车)
Another sources of race conditions are interrupts and signals. If you use neither then no race condition will occur (there is single racer)
任何时候进行系统调用都有可能出现竞争条件。这是因为内核链接了系统上的所有线程并允许进程之间的控制交互。在这种情况下,系统上的另一个线程可以访问与您的应用程序相同的文件。
Any time that you make a system call there is a possibility of a race condition. This is because the kernel links all the threads on the system and allows control interaction between processes. In this case another thread on the system can access the same file as your application.
boost::filesystem 文档对一般适用于文件系统的文件系统竞争条件有很好的解释。
The boost::filesystem docs have good explanations of filesystem race conditions which are applicable to filesystems in general.