The Mechanism to prevent corruption from multi-threading

67 views
Skip to first unread message

蘇思暢

unread,
Mar 23, 2016, 1:38:51 AM3/23/16
to drones-discuss
Hi everyone,
I am just wondering how APM handles the multi-threading and prevent corruption due to multi-threading.
It mentions the lockless data structure which is ringbuffer can prevent corruption from multi-threading.
And i read the code of UARTDriver.cpp in AP_HAL_PX4 folder, but _writebuf is just a buffer to store the data to be sent and i don't see how this works to prevent corruption from multi-threading.
Could anyone help me to solve this?

Thanks,
Best Regards

Victor Su

Randy Mackay

unread,
Mar 23, 2016, 3:12:39 AM3/23/16
to drones-...@googlegroups.com

Victor,

 

      I don’t think I have the full answer for you but my guess is that only one thread ever writes to the UARTs.  So the main thread which is sending the telemetry data down to the GCSs would be writing to the telemetry UARTs but these same UARTs wouldn’t be written to by the background threads doing things like reading sensor data from the IMU.

 

    I think the only exception to this might be the console but I think corruption on the console is ok because it’s not used for communicating with anything, it’s just for logging and display in case some developer happens to be connected to it.

 

-Randy

--
You received this message because you are subscribed to the Google Groups "drones-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drones-discus...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

蘇思暢

unread,
Mar 23, 2016, 4:20:07 AM3/23/16
to drones-discuss
Hi Randy,
Thanks for your kind answer. After i posted the question i reviewed the AP_Scheduler and i found all the accessing to the telem1 UART are in the same thread as you mentioned therefore no thread unsafety problem.

Thanks,
Best regards

Victor
Reply all
Reply to author
Forward
0 new messages