You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2020/08/14 15:22:01 UTC

[GitHub] [incubator-nuttx] anchao commented on pull request #1585: sched/task: do not migrate the task state to INVALID

anchao commented on pull request #1585:
URL: https://github.com/apache/incubator-nuttx/pull/1585#issuecomment-674126688


   This issue is caused by mqueue_inode_s:nwaitnotempty flag mismatch,
   From the code view, if we Kill a thread that is pending for mq_receive(2):
   
   ```
   nxtask_terminate
   |
    ->dtcb->task_state = TSTATE_TASK_INVALID;  <--- task state has been switched to invalid 
    ->nxtask_exithook
      |
       ->nxtask_recover
         |
          ->nxmq_recover
   ```
   
   ```
   void nxmq_recover(FAR struct tcb_s *tcb)
   { 
   ...
     if (tcb->task_state == TSTATE_WAIT_MQNOTEMPTY)    <--- state already change to the invalid
       { 
   ...
         tcb->msgwaitq->nwaitnotempty--;               <---  nwaitnotempty remain 1
       }
     else if (tcb->task_state == TSTATE_WAIT_MQNOTFULL)
       { 
         DEBUGASSERT(tcb->msgwaitq && tcb->msgwaitq->nwaitnotfull > 0);
         tcb->msgwaitq->nwaitnotfull--;
       }
   }
   ```
   
   Since the nwaitnotempty is still 1, if the application triggers mq_send here, the system will trigger assert 
   
   ```
   int nxmq_do_send(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg,
                    FAR const char *msg, size_t msglen, unsigned int prio)
   {
    ...
     if (msgq->nwaitnotempty > 0)
       {
   ...
         DEBUGASSERT(btcb);
   ...
   }
   ```
   
   To fix this issue, we must delay the task state switch after recover() call, but if the state switch just after recover(), there is no reason to change the state, cecause TCB will be destroyed soon, so it is better to remove the state invalid switch.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org