I have the following situation:
There are a thousand processes and each of them has the following task:
1) choose a nr X from 1 to 1 000
2) if X.txt does exists, go to (1)
3) Open X.txt and write "hello this is process_id".
Now, my question is, if I use open('X.txt', 'wx')
is it possible that at some point 2 processes will be able to open the file the same time, because they will at the same time say: "ok, X.txt doesnt exist, so lets open it for writing"?
If it is possible, is there a safety mechanism I could use, for example when I close the file, check if I was the only process that was writing to this file?