make mutex thread-safe