MBX functions send_if, receive_wp not atomic?
M. Koehrer
mathias_koehrer at arcor.de
Tue Jun 1 14:07:21 CEST 2004
Hi everybody!
I have found a strange behaviour concerning rt_mbx_send_if and
rt_mbx_receive_wp - I think these functions are not atomic as
expected!
I have a LXRT user space task that sends data to a kernel task
using rt_mbx_send_if. The number of data to be send varies.
The counter part - the kernel task - reads this data via
rt_mbx_receive_wp. It tries to read a maximum size, the actual size
that is placed in the MBX by the user space task is determined by
using the return value of rt_mbx_receive_wp.
Both tasks (user space and kernel task) run completely unsynchronized.
I expected these communication between user and kernel space to be
atomic. However, what I found out is that this seems not to be true.
I run regularly in the situation that the user space task places e.g.
400 byte in the MBX (with rt_mbx_send_if) but the kernel task seems
not to receive all 400 bytes, the missing bytes will be read by the
succeeding call of rt_mbx_receive_wp together with the next data
packet.
The following figure shows the behaviour:
User Task Kernel Task
Send 500 byte Receive 500 byte (OK)
Send 400 byte Receive 392 byte (ERROR)
Send 200 byte Receive 208 byte (200 + 8 from the previous call)
This leads to invalid data packets.
What I have done to fix this to encapsulate the calls to
rt_mbx_send_if and rt_mbx_receive_wp within semaphore protection. This
works fine then.
But it seems to me as if these MBX functions are actually not atomic
as expected.
Any hints or comment on this are welcome!
I am using rtai-3.0, rthal5-g
Thanks
Mathias
--
Mathias Koehrer
mathias_koehrer at arcor.de
More information about the Rtai
mailing list