Test case for the locking stuff.

Probably not particularly great at finding issues on all platforms.
Notably Windows doesn't seem to crash without it anyway.