Examples in SDK15 use the Observer pattern to handle BLE events (using the macro NRF_SDH_BLE_OBSERVER). AFAIK, the registered handler runs in some IRQ context, typically higher then my main context.
Looking at the experimental ble_app_interactive example, I see that some data structures (e.g. m_device in ble_m.c) are accessed from both the observer context, and the main context, without synchronization:
- in ble_m.c device_to_list_add() is called from the observer context, and modifies m_device
- in main.c an app_timer call to scan_device_info_clear() clears m_device
Questions:
- Is the code in the example valid, or should access to m_device be synchronized?
- If synchronization is needed, what is the recommended way to synchronize between the observer and the main thread?
Example was taken from nRF5_SDK_15.0.0_a53641a