Test spinlock based threading

Mutexes deadlocked sometimes in initial tests. This spinlock
method seems to work but wastes a lot of CPU so it's not an
adequate solution either.