Merge pull request #24581 from vrabaud:tsan

Fix race condition in color_lab.cpp initLabTabs(). #24581

There is a race condition between when the static bool is initialized (which is thread safe) and its value check. This PR changes the static bool to a static lambda call to make it thread safe. The static_cast<void> in the end is to prevent unused variables warnings.

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
pull/24599/head
Vincent Rabaud 1 year ago committed by GitHub
parent 49463c4420
commit 06f62a3dd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      modules/imgproc/src/color_lab.cpp

@ -1223,11 +1223,8 @@ static LABLUVLUT_s16_t initLUTforLABLUVs16(const softfloat & un, const softfloat
}
static void initLabTabs()
static bool createLabTabs()
{
static bool initialized = false;
if(!initialized)
{
softfloat f[LAB_CBRT_TAB_SIZE+1], g[GAMMA_TAB_SIZE+1], ig[GAMMA_TAB_SIZE+1];
softfloat scale = softfloat::one()/softfloat(LabCbrtTabScale);
int i;
@ -1333,9 +1330,13 @@ static void initLabTabs()
}
}
}
return true;
}
initialized = true;
}
static bool initLabTabs()
{
static bool initialized = createLabTabs();
return initialized;
}

Loading…
Cancel
Save