Crossover for Work Interview Question

Threads Race condition

Interview Answer

Anonymous

May 11, 2017

A race condition occurs when two or more threads can access shared data and they try to change it at the same time. In order to prevent race conditions from occurring, you would typically put a lock around the shared data to ensure only one thread can access the data at a time. Once the thread finishes working on the data, it has to release the lock so the second lock can perform the operation on the data. Some concepts in java such as mutex, semaphore, critical section, shared resource are used to help working with this condition.