/* Detach a thread (thread storage can be reclaimed when thread terminates).  */
static osStatus_t svcRtxThreadDetach(osThreadId_t thread_id)
/* Detach a thread (thread storage can be reclaimed when thread terminates).  */
static osStatus_t svcRtxThreadDetach(osThreadId_t thread_id)
{
    EvrRtxThreadError(thread, (int32_t)osErrorParameter);
    return osErrorParameter;
  }
  if ((thread->attr & osThreadJoinable) == 0U) {
    EvrRtxThreadError(thread, osRtxErrorThreadNotJoinable);
    return osErrorResource;
  }
  if (thread->state == osRtxThreadTerminated) {
    osRtxThreadListUnlink(&osRtxInfo.thread.terminate_list, thread);
    osRtxThreadFree(thread);
  } else {
    thread->attr &= ~osThreadJoinable;
  }
  EvrRtxThreadDetached(thread);
  return osOK;
}