Fix behaviour when pthreads/bsdsocket are used together - thanks to Fabio Alemagna...