mavlink / c_uart_interface_example

Simple MAVLink to UART interface example for *nix systems
264 stars 257 forks source link

current_setpoint should be guarded with a mutex #33

Closed allsey87 closed 3 years ago

allsey87 commented 3 years ago

I have been going through this code and thought I would point out that current_setpoint is written from the main thread and read from the writing thread without any protection (i.e., a mutex or a lock). Although unlikely, it possible that current_setpoint is read by the writing thread while being written from the main thread which could result in things going to hell very quickly since we are talking about a quadcopter or similar here.

In contrast to this, I am almost certain that reading and writing to the serial port from different threads just works in POSIX and doesn't need any mutexes.

hamishwillee commented 3 years ago

@allsey87 We'd welcome a PR! @julianoes FYI

allsey87 commented 3 years ago

Well, I have used this as a starting point to write my own MAVLink interface for integration into the ARGoS Simulator. During this process, I have made a far more simplified version of this example which I can share with you if you are interested

hamishwillee commented 3 years ago

@allsey87 Yes, would appreciate a PR of new/updated example. I'm not particularly good at C/C++ but I'll ask another team member to look at it.

hamishwillee commented 3 years ago

Fixed. Closing :-). Thanks! Still interested in a PR if you think it better highlights how to approach this problem.