Add naive synchronization via Mutex#lock and Mutex#unlock to make it a little bit more thread-safe.

Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>