fixed wrong use of errno in error conditions after a call to a pthread function