Algorithm set/info not threadsafe (Bug #2697)


Added by daniel oberhoff about 12 years ago. Updated over 9 years ago.


Status:Open Start date:2013-01-14
Priority:Low Due date:
Assignee:Vadim Pisarevsky % Done:

0%

Category:core
Target version:-
Affected version:2.4.6 (latest release) Operating System:Any
Difficulty: HW Platform:Any
Pull request:

Description

Hi,

I make heavy use of threads and lazy initialization in my code. But it seems anything related to the new algorithm info infrastructure is not thread safe. And I mean not when applied on a single instance, but across a whole class. I.e. when I retreive the info simultanously for separate instances of the same class, I get a segfault. same for setting, and again, these are separate instances.

If you wish I can generate stack traces for you.

btw it would be nice, if algorithm parameters where somehow documented somewhere.

Best


main.cpp (834 Bytes) Vladislav Vinogradov, 2013-09-30 09:56 am


Related issues

related to Bug #3292: changing brisk detector parameter while in a concurency p... Cancelled 2013-09-27

Associated revisions

Revision eb240cc2
Added by Alexander Alekhin almost 11 years ago

Merge pull request #2697 from PhilLab:master

History

Updated by Marina Kolpakova about 12 years ago

  • Category set to core
  • Assignee set to Vadim Pisarevsky

Updated by Vadim Pisarevsky about 12 years ago

without a sample code it's not possible to reproduce the problem. setting Algorithm properties should be thread-safe. info() method is not completely thread-safe, the first invocation may do some initialization, but the problem should not appear in the existing OpenCV classes.

so, please, provide the sample code so that we can reproduce the problem

  • Assignee changed from Vadim Pisarevsky to daniel oberhoff
  • Affected version set to 2.4.3
  • Priority changed from Normal to Low

Updated by Vladislav Vinogradov over 11 years ago

Hello Vadim,

There is a new report with the same issue : http://code.opencv.org/issues/3292

I attached a sample code that reproduce the issue (tested on Linux with TBB).

Algorithm::info is implemented in the following way:

::cv::AlgorithmInfo* classname::info() const
{
    static volatile bool initialized = false;
    if( !initialized )
    {
        initialized = true;
        memberinit;
    }
    return &classname##_info();
}

There is no synchronization between threads.
So one thread can set initialized variable to true and go to sleep before memberinit, while the second thread will read initialized value as true and will use uninitialized struct.

  • Assignee changed from daniel oberhoff to Vadim Pisarevsky
  • HW Platform set to Any
  • Operating System set to Any
  • Affected version changed from 2.4.3 to 2.4.6 (latest release)
  • File main.cpp added

Updated by Maksim Shabunin over 9 years ago

Issue has been transferred to GitHub: https://github.com/Itseez/opencv/issues/4485

Also available in: Atom PDF