pthread_detach() returns zero when the call completes successfully. Any other return value indicates that an error occurred. When any of the following conditions is detected, pthread_detach() fails and returns the corresponding value.
EINVAL
Description:tid is a detached thread.
ESRCH
Description:tid is not a valid, undetached thread in the current process.