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

Fix for issue #85

Fixed wrong use of errno in error conditions after a call to a pthread function