Race conditions are an integral part of non-determinism. If you cannot guarantee that the calling sequence is secure, enter some run-time checks that check protocol invariants. Then, at least, you will have evidence of an error when they occur.
Although this does not solve your problem, it at least gives you a tool to quantify the extent of the problem.
If any race is triggered from events outside the application area, then any static analysis would require that it also be modeled in order to be able to detect conditions.
Pekka source share