whitecatboard / Lua-RTOS-ESP32

Lua RTOS for ESP32
Other
1.19k stars 221 forks source link

mtx_lock() occurs in two times #1

Closed edbek closed 7 years ago

edbek commented 7 years ago

mtx_lock() function occurs in two times in pthread_create(). So it should be?

mtx_lock(&thread->init_mtx);

    // Create related task
    res = xTaskCreate(
            pthreadTask, "lthread", stacksize, taskArgs,
            tskDEF_PRIORITY, &xCreatedTask
    );

    if(res != pdPASS) {
        // Remove from thread list
        list_remove(&thread_list,*id);
        free(taskArgs);
        free(thread);

        if (res == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY) {
            errno = ENOMEM;
            return ENOMEM;
        } else {
            errno = EAGAIN;
            return EAGAIN;
        }
    }

    mtx_lock(&thread->init_mtx);
jolivepetrus commented 7 years ago

This is correct, it's mandatory for Lua RTOS pthread management.

After the creation of the new task related to new thread we need to wait for the initialization of critical information that is provided by new thread:

This is done by pthreadTask function, who releases the lock when this information is set.

We have document this in our last commit https://github.com/whitecatboard/Lua-RTOS-ESP32/commit/fb44da2fe2c93128eb833b042ccf13838a5ba4eb

jolivepetrus commented 7 years ago

Let me to close this issue. No feedback were provided.