Fix thread safety bug.
The previous attempt to resolve it with had a flaw. It is now using a mutex used with trylock() to avoid affecting performance.
The previous attempt to resolve it with had a flaw. It is now using a mutex used with trylock() to avoid affecting performance.