没有线程的竞争条件?

发布于 2024-09-13 17:34:38 字数 303 浏览 10 评论 0原文

假设我有: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

暮倦 2024-09-20 17:34:38

存在一种竞争条件,即用户可以在您更改“新文件”的权限之前立即交换“新文件”。这是(曾经?)经常使用的安全漏洞。

我只是看到尼尔巴特沃斯有一个相关的想法。

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.

分開簡單 2024-09-20 17:34:38

存在竞赛的可能性 - 两个用户可以同时运行您的程序。

There is the possibility of a race - two users could run your program at the same time.

从此见与不见 2024-09-20 17:34:38

竞争条件的另一个来源是中断和信号。如果两者都不使用,则不会发生竞争条件(只有一个赛车

Another sources of race conditions are interrupts and signals. If you use neither then no race condition will occur (there is single racer)

风吹雨成花 2024-09-20 17:34:38

任何时候进行系统调用都有可能出现竞争条件。这是因为内核链接了系统上的所有线程并允许进程之间的控制交互。在这种情况下,系统上的另一个线程可以访问与您的应用程序相同的文件。

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.

青瓷清茶倾城歌 2024-09-20 17:34:38

boost::filesystem 文档对一般适用于文件系统的文件系统竞争条件有很好的解释。

The boost::filesystem docs have good explanations of filesystem race conditions which are applicable to filesystems in general.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文