Race condition and synchronized locking of shared resources