/* Create and start a thread. 
This function starts a new thread. The new thread starts execution by invoking entry(). The argument arg is passed as the sole argument of entry(). */
OS_Status OS_ThreadCreate(OS_Thread_t *thread, const char *name, OS_ThreadEntry_t entry, void *arg, OS_Priority priority, uint32_t stackSize)
/* Create and start a thread. 
This function starts a new thread. The new thread starts execution by invoking entry(). The argument arg is passed as the sole argument of entry(). */
OS_Status OS_ThreadCreate(OS_Thread_t *thread, const char *name, OS_ThreadEntry_t entry, void *arg, OS_Priority priority, uint32_t stackSize)
{
    OS_HANDLE_ASSERT(!OS_ThreadIsValid(thread), thread->handle);
    thread->handle = rt_thread_create(name, entry, arg, stackSize,
                                      priority, 20);
    OS_DBG("%s(), name \"%s\", priority %d, stackSize %u, handle %p\n",
           __func__, name, priority, (unsigned int)stackSize, thread->handle);
    if (thread->handle == NULL) {
        OS_ERR("rt_thread_create() failed!\n");
        OS_ThreadSetInvalid(thread);
        return OS_FAIL;
    } else {
        rt_thread_startup(thread->handle);
    }
    return OS_OK;
}