Fix return code which is an error occurred at pthread function