replaced busy waiting with mutex