Added more locking to stop starvation.