This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

race condition sd_ble_gatts_value_set

Hi,

I'm using s132, sdk 12.1 on nrf52x, my question is about possible race condition when setting the value of a characteristic using sd_ble_gatts_value_set (on peripheral) and at the same time the central is reading the characteristic let's say by doing read request without authorization? Is there a possibility of a race condition? How is it implemented in softdevice?

Parents
  • Hi Jan,

    Yes, sd_ble_gatts_value_set just writes the value to the attribute identified by the handle passed as an argument. The central Read Request without authorization will simply return the current value in the GATT table of the GATT Server. Thus, if the new value has not been written to the GATT Server table when the Read Request is received, then it will return the current, i.e. "old" characteristic value.

    Strictly speaking, this is not a race condition as this is behavior is in compliance with the Bluetooth Core Specification.

    If it is important that the new characteristic value is passed to the central as soon as possible after the new value has been written to the GATT Server Table, then I recommend using Notification or Indication to pass the value to the central, i.e. first call sd_ble_gatts_value_set and then sd_ble_gatts_hvx to notify/indicate the characteristic value.

  • Ok thanks, I just wnated to be sure that SoftDevice prevents the value to be corrupted by concurrent reading and writing.

Reply Children
No Data
Related