replace spin locks with mutexes, fix build on OS X

closes #293