kaykun kaykun - 1 month ago 6x
C Question

Is open thread safe?

Is it okay if two threads call open() at the same time? How would one find the answer to this question?

Assume that the calls are operating on different files, and their flags can be

, or both.


Since you note they are different files, then there isn't a problem.

It's no different that two different processes opening two different files.

Edit: It would be fair to mention, as Guy notes below in the comments, that this was not always the case. It is dependent on whether the libc you are using is threadsafe. Modern incarnations are in regard to the open() call.