request.req_args.free.thread = th;
request.req_args.free.thread_id = thread_id;
int pthread_detach(pthread_t thread_id){  int terminated;  struct pthread_request request;  pthread_handle handle = thread_handle(thread_id);  pthread_descr th;  __pthread_lock(&handle->h_lock);  if (invalid_handle(handle, thread_id)) {    __pthread_unlock(&handle->h_lock);    return ESRCH;  }  th = handle->h_descr;  /* If already detached, error */  if (th->p_detached) {    __pthread_unlock(&handle->h_lock);    return EINVAL;  }  /* If already joining, don't do anything. */  if (th->p_joining != NULL) {    __pthread_unlock(&handle->h_lock);    return 0;  }  /* Mark as detached */  th->p_detached = 1;  terminated = th->p_terminated;  __pthread_unlock(&handle->h_lock);  /* If already terminated, notify thread manager to reclaim resources */  if (terminated && __pthread_manager_request >= 0) {    request.req_thread = thread_self();    request.req_kind = REQ_FREE;    request.req_args.free.thread = th;    __libc_write(__pthread_manager_request,		 (char *) &request, sizeof(request));  }  return 0;}