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 possi开发者_如何学Pythonbility of a race condition here since I have no threads in my main() method. Is that true?
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.
The boost::filesystem docs have good explanations of filesystem race conditions which are applicable to filesystems in general.
精彩评论