Make cleaner threads.h compile for the NOTHREADS case
__attribute__(visibility) only works for gcc newer than 4.1.2
Fix for old versions of msvc
Fixes for FreeBSD