Use pthread_spin unless it has been disabled
Use smarter initialization logic.
Fix linux compilation