Does Mailbox block other threads?

Discussions and support about ChibiOS/RT, the free embedded RTOS.
Post Reply
carldong
Posts: 62
Joined: Wed Oct 15, 2014 6:08 pm
Has thanked: 1 time
Been thanked: 1 time

Does Mailbox block other threads?

Post 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?
carldong
Posts: 62
Joined: Wed Oct 15, 2014 6:08 pm
Has thanked: 1 time
Been thanked: 1 time

Re: Does Mailbox block other threads?

Post 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?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Does Mailbox block other threads?

Post by Giovanni »

Blocking calls always give control to other threads unless you see "Polled" in the function name.

Giovanni
Post Reply