better synchronization using mutex