If an error condition occurs, this routine returns an integer
indicating the type of error. Possible return values are as
follows:
Return Description
0 Successful completion.
[EINVAL] The value specified by thread does not refer to a
joinable thread.
[ESRCH] The value specified by thread does not refer to an
existing thread ID.
[EDEADLK] A deadlock was detected, or thread specifies the
calling thread.