/* Detach a thread (thread storage can be reclaimed when thread terminates).  */
osStatus_t osThreadDetach(osThreadId_t thread_id)
/* Detach a thread (thread storage can be reclaimed when thread terminates).  */
osStatus_t osThreadDetach(osThreadId_t thread_id)
{
	struct cv2_thread *tid = (struct cv2_thread *)thread_id;
	if ((tid == NULL) || (is_cmsis_rtos_v2_thread(tid) == NULL)) {
		return osErrorParameter;
	}
	if (k_is_in_isr()) {
		return osErrorISR;
	}
	if (_is_thread_cmsis_inactive(&tid->z_thread)) {
		return osErrorResource;
	}
	__ASSERT(tid->attr_bits != osThreadDetached,
		 "Thread already detached, behaviour undefined.");
	tid->attr_bits = osThreadDetached;
	k_sem_give(&tid->join_guard);
	return osOK;
}