Thread safety through atomic access.

Closes issue #1.