This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

F28069 Mutex Best Practice

I have a queue for holding CAN messages. In the CAN ISR, when a message is received, it is put into the queue. In the main loop, messages are taken out of the queue.

I want to have a mutex when putting messages in the queue and when messages are taken out. What is the best why to do this?

  • There are a number of mutex algorithms available online, but I don't think a mutex is what you need here. It's probably better to disable interrupts while you remove messages from the queue in the main loop. ISRs don't run concurrently with the main loop, they preempt it. If the main loop has the lock, the ISR will deadlock or starve.