rcutils icon indicating copy to clipboard operation
rcutils copied to clipboard

rcutils_get_zero_initialized_string_array has (potential) data race

Open comicfans opened this issue 1 year ago • 2 comments

hello, during thread sanitizer test, I've found multi thread calling into rcutils_get_zero_initialized_string_array gives data race warnings from thread sanitizer

https://github.com/ros2/rcutils/blob/rolling/src/string_array.c#L35

rcutils_string_array_t
rcutils_get_zero_initialized_string_array(void)
{
  static rcutils_string_array_t array = {
    .size = 0,
    .data = NULL,
  };
  array.allocator = rcutils_get_zero_initialized_allocator();  //.  <---- thread sanitizer report data race this line because caller on some other thread may read it, but every threading running this line is write to it, without synchronize
  return array;
}

this may behave correctly on some architect, but still a data race in C standard

comicfans avatar Sep 04 '24 20:09 comicfans