Does there exist a test framework for C that forces race conditions?
Or for C++ and Java, for that matter.
Race conditions are inherently a result of non-determinism. If you cannot ensure that the calling sequence is secure, then introduce a number of run-time checks that verify the protocol invariants are honoured. Then, at least you will have evidence of a fault whenever they occur.
To avoid race conditions, any operation on a shared resource – that is, on a resource that can be shared between threads – must be executed atomically. One way to achieve atomicity is by using critical sections — mutually exclusive parts of the program.
Basically, people detect race condition problem in two big category methods. The first one is detecting in the compile time, which is also called static detection; the other is detection in the run time, which is called dynamic detecting. Both of these two have shortcomings such as coverage, speed, etc.
Race Detection Algorithms. The lockset algorithm, used in both static and dynamic analysis tools, reports a potential race when shared memory is accessed by two or more threads without the threads holding a common lock.
The Valgrind tool Helgrind detects (among other things) data races in C or C++ programs that use pthreads.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With