Sorry for the long title, but I think it explains well what I’m interested in. For example C function strtok is not thread safe in worst possible way 🙂 , it uses a global state. So even if it is called on different data it is not thread safe.
So my question is are there functions in “C++ minus C” that have same problem.
Again I’m not interested in things like “if you write to same file from 10 threads it is undefined behavior”. What I’m interested is “if you write to 2 diff files from 2 diff threads (each thread writes to its own file )that is not thread safe.”
Sorry for the long title, but I think it explains well what I’m interested
Share
Thread safety is only really covered by C++11; C++03 didn’t specify multi-threaded behavior.
In C++11, the relevant bits are 1.10/8 “Certain library calls synchronize with other library calls performed by another thread. For example, an atomic store-release synchronizes with a load-acquire that takes its value from the store (29.3).” and especially §17.6.5.9 Data race avoidance.
The cases you mention are obviously disallowed: “
Where the text above says “unless otherwise specified”, it includes some C function, e.g. (27.9.2/2) “Calls to the function
tmpnamwith an argument ofNULLmay introduce a data race (17.6.5.9) with other calls totmpnamwith an argument ofNULL.”