Page 1 of 1

Does Mailbox block other threads?

Posted: Thu Apr 06, 2017 9:36 pm
by carldong
I tried to use mailbox + memory pool as a FIFO to communicate between threads. Currently, I tested this configuration on the receiving thread:

Code: Select all

    chMBFetch(&mb, (msg_t *)p, TIME_INFINITE);


where `p` is actually a pointer to something in a memory pool. However, as I observed, this line seems to block all other threads. I am not sure whether it is expected. It is possible to use `TIME_IMMEDIATE` and then insert a manual delay, but I don't like that solution.

Maybe mailbox is not the best way to do it, but I can't think of other methods for now.

BTW, how should I see whether a certain action will yield the execution to other threads? I know event waiting yields, sleeps also does, but what about other things, like sdPutTimeout and such?

Re: Does Mailbox block other threads?

Posted: Thu Apr 06, 2017 9:40 pm
by carldong
Ah, stupid me... 10 seconds after I posted this, I noticed that I should pass

Code: Select all

(msg_t *) &p
instead of

Code: Select all

(msg_t *) p
. Unfortunately `-Werror=all` didn't capture this one...

And indeed this operation yields to other threads. Can I assume anything in ChibiOS that requires waiting will yield to other threads?

Re: Does Mailbox block other threads?

Posted: Fri Apr 07, 2017 7:47 am
by Giovanni
Blocking calls always give control to other threads unless you see "Polled" in the function name.

Giovanni