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/07/06 16:45:58 UTC

[GitHub] [incubator-nuttx] lukegluke edited a comment on issue #1354: Bug in can driver: wrong use of nxsem_get_value

lukegluke edited a comment on issue #1354:
URL: https://github.com/apache/incubator-nuttx/issues/1354#issuecomment-654344084


   While investigating the issue in can, I've examined nxsem_wait and nxsem_post and didn't get how it suppose to work right for thread + thread case.
   
   Semaphore can has two holders inside holder[2]. Let say two tasks have one thread each, and we are sync these threads by waiting on semaphore. CONFIG_SEM_PREALLOCHOLDERS is 0.
   
   _nxsem_wait_ in first thread add "thread1" htcb to holder[0], then _nxsem_wait_ in second thread fill holder[1] with "thread2" htcb.
   Then nxsem_post in first thread release holder[0] and 
   > Check if there are any tasks in the waiting for semaphore task list that are waiting for this semaphore
   
    and found "task2" htcb (not the "thread2" htcb) and within _nxsem_addholder_tcb_ will fill holder[0]. Now holder[0] is occupied by htcb that will not get freed.
   If situation repeats again, there will be no place for "thread2" -> DEBUGASSERT(pholder != NULL) in nxsem_allocholder.
   
   Why if in nxsem_wait this_task() that return htcb of thread is used, in nxsem_post list of **tasks** waiting for semaphore is used, but not all threads?
   
   I'm not good in shed stuff, am I missing something?


----------------------------------------------------------------
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