eProsima / Micro-XRCE-DDS-Client

Micro XRCE-DDS Client repository. Looking for commercial support? Contact info@eprosima.com
Apache License 2.0
130 stars 82 forks source link

Unlock stream after locking while stream preparing #363

Closed dzusan closed 1 year ago

dzusan commented 1 year ago

Using uxr_prepare_output_stream() in two concurrent threads of FreeRTOS before uxr_run_session_until_confirm_delivery() blocks one of the threads forever due the stream_id not being unlocked after locking. In other words, a recursive mutex is taken and given an unequal number of times.

pablogs9 commented 1 year ago

Hello @dzusan, sorry if this is not well documented or has examples, but when preparing the buffer the session lock is not unlocked on purpose because after the "buffer preparation" is expected that the user writes the payload in the prepared buffer. So it is the user responsible for unlocking the session.

This is why the session is unlocked only when the buffer prepare fails.

You can see an example of the usage at application level here: https://github.com/micro-ROS/rmw_microxrcedds/blob/bc4eb312ac4601a4137c35f4a56b9b83b4b18339/rmw_microxrcedds_c/src/rmw_publish.c#L76

richiprosima commented 1 year ago

Build status:

dzusan commented 1 year ago

Oh, thank you @pablogs9 With UXR_UNLOCK_STREAM_ID in user code it works properly. You can close the PR. But I would like to see a little note about the need to give mutex manually in brief of each function that requires it.

pablogs9 commented 1 year ago

It is only in the buffer preparation methods. We will document it.