mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
core/mbox: fix race condition
The mbox code contains a race condition in `mbox_put()`: When it waits for a slot in the queue to become available, it is woken up with IRQs enabled. It disables IRQs again as first thing, but by then another thread may already have preempted the running thread and filled the queue back up. In this case, a message in the queue would be silently overwritten.
This commit is contained in:
parent
54b0100c44
commit
42b9334784
@ -73,7 +73,7 @@ int _mbox_put(mbox_t *mbox, msg_t *msg, int blocking)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (cib_full(&mbox->cib)) {
|
while (cib_full(&mbox->cib)) {
|
||||||
if (blocking) {
|
if (blocking) {
|
||||||
_wait(&mbox->writers, irqstate);
|
_wait(&mbox->writers, irqstate);
|
||||||
irqstate = irq_disable();
|
irqstate = irq_disable();
|
||||||
|
Loading…
Reference in New Issue
Block a user