-
Notifications
You must be signed in to change notification settings - Fork 576
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
os/kernel: pthread_mutex_* functions is called in non-pthread task #2969
Comments
I checked latest code of Nuttx, static void pthread_mutex_add(FAR struct pthread_mutex_s *mutex)
{
FAR struct tcb_s *rtcb = this_task();
DEBUGASSERT(mutex->flink == NULL);
/* Check if this is a pthread. The main thread may also lock and unlock
* mutexes. The main thread, however, does not participate in the mutex
* consistency logic. Presumably, when the main thread exits, all of the
* child pthreads will also terminate.
*
* REVISIT: NuttX does not support that behavior at present; child pthreads
* will persist after the main thread exits.
*/
if ((rtcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_PTHREAD)
{
FAR struct pthread_tcb_s *ptcb = (FAR struct pthread_tcb_s *)rtcb;
irqstate_t flags;
/* Add the mutex to the list of mutexes held by this pthread */
flags = enter_critical_section();
mutex->flink = ptcb->mhead;
ptcb->mhead = mutex;
leave_critical_section(flags);
}
} |
if so, then it is really risky to invoke pthread_mutex_* in non-pthread task, causing undefined behavior which is hard to find the root cause. |
@zhouxinhe @xixidodo Next week, I will check all of pthread APIs and will update them. |
@zhouxinhe Thank you for notice |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I can find codes (invoking pthread_mutex_(un)lock() in non-pthread task) in TizenRT:
when pthread_mutex_lock() is called, pthread_mutex_add() would be executed (in case CONFIG_PTHREAD_MUTEX_UNSAFE isn't defined)...
in above code, it assumes that current task is a pthread task.
but it's not sure, so I try to add below assertion code in pthread_mutex_add():
then I found asstion as below:
It's related to file os\drivers\wireless\scsccm_if.c (wifi is enabled).
--- Idle task is not a pthread task!
when I disabled wifi and then I got same assertion in example app code.
--- "appmain" task is not a pthread task!
I can not list all assertioins here...
My questions:
pthread_mutex_ functions should be only called in pthread task, right?
DEBUGASSERT
above and then fix the assertions.Any change in task management fields of struct pthread_tcb_s will damage the task management fields of real struct task_tcb_s (beause current task is non-pthread task);
or maybe overwrite memory of next neighboring node (e.g.
rtcb->mhead
's offset may be larger than sizeof(struct task_tcb_s)).The text was updated successfully, but these errors were encountered: