replace busy waiting with rwlocks