Does Mailbox block other threads?

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

Does Mailbox block other threads?

Postby carldong » Thu Apr 06, 2017 9:36 pm

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?

Postby carldong » Thu Apr 06, 2017 9:40 pm

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: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Does Mailbox block other threads?

Postby Giovanni » Fri Apr 07, 2017 7:47 am

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

Giovanni


Return to “ChibiOS/RT”

Who is online

Users browsing this forum: No registered users and 11 guests