Skip to content

Thread sanitizer triggers in parallel_impl.cpp #19463

@vrabaud

Description

@vrabaud
System information (version)
  • OpenCV => 4.5.1
  • Operating System / Platform => Linux
  • Compiler => clang
Detailed description

Our thread sanitizer finds a race condition:

WARNING: ThreadSanitizer: data race (pid=3836)
Read of size 1 at 0x7b240000e1e8 by main thread:
#0 cv::ThreadPool::run(cv::Range const&, cv::ParallelLoopBody const&, double) third_party/OpenCV/v4_5_1/modules/core/src/parallel_impl.cpp:574:32
#1 cv::parallel_for_pthreads(cv::Range const&, cv::ParallelLoopBody const&, double) third_party/OpenCV/v4_5_1/modules/core/src/parallel_impl.cpp:731:28
#2 parallel_for_impl third_party/OpenCV/v4_5_1/modules/core/src/parallel.cpp:584:9
#3 cv::parallel_for_(cv::Range const&, cv::ParallelLoopBody const&, double) third_party/OpenCV/v4_5_1/modules/core/src/parallel.cpp:512:13
....

Previous write of size 1 at 0x7b240000e1e8 by thread T14 (mutexes: write M16796):
#0 cv::WorkerThread::thread_body() third_party/OpenCV/v4_5_1/modules/core/src/parallel_impl.cpp:396:22
#1 cv::WorkerThread::thread_loop_wrapper(void*) third_party/OpenCV/v4_5_1/modules/core/src/parallel_impl.cpp:278:41

It seems IsActive is set in the thread with no mutex at

isActive = false;
while the threadpool can read by the main thread at
thread.isActive ||

CV_USE_GLOBAL_WORKERS_COND_VAR is not defined.
Defining it solves the issue. Do we want to have code that is not thread-safe by default ?

Issue submission checklist
  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues,
    forum.opencv.org, Stack Overflow, etc and have not found solution
  • I updated to latest OpenCV version and the issue is still there

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions