In this repository, different variants of a multi-threaded Java program are shown that deal with data
races while accessing a shared variable counter:
- No protection at all, just access
counter, so lots of data races happen. - Still no protection, but the execution time of the threads is very short, so all access happens in the first time slot and the probability for a data race is quiet low. Nevertheless, data races can happen.
- Atomic integer. No data races. Best solution for this type of synchronization problem.
- Using a synchronized method. No data races anymore but no parallelism either; the threads are all serialized.
- Synchronized block while the counter variable is accessed. No data races.
- Sempahores. No data races.
- Reentrant locks. No data races.