Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mtx_lock() occurs in two times #1

Closed
edbek opened this issue Nov 16, 2016 · 2 comments
Closed

mtx_lock() occurs in two times #1

edbek opened this issue Nov 16, 2016 · 2 comments

Comments

@edbek
Copy link

edbek commented Nov 16, 2016

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
Copy link
Contributor

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:

  • Allocate Lua RTOS specific TCB parts, using local storage pointer assigned to pthreads
  • The thread id, stored in Lua RTOS specific TCB parts
  • The Lua state, stored in Lua RTOS specific TCB parts

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

We have document this in our last commit fb44da2

@jolivepetrus
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants