OpenCV functions are not re-entrant (Bug #2462)


Added by Johannes Jordan over 12 years ago. Updated over 12 years ago.


Status:Cancelled Start date:2012-10-20
Priority:High Due date:
Assignee:Vadim Pisarevsky % Done:

0%

Category:core
Target version:2.4.3
Affected version: Operating System:
Difficulty: HW Platform:
Pull request:

Description

Several OpenCV functions make use of static const variables for their computations. The problem is that these variables are static. If OpenCV is called in a multi-threaded scenario, several threads may initialize these variables at the same time. The initialization of a static variable is not atomic, in fact it is two operations: Setting an init flag for the variable, then setting the variable itself.
As a result, the first function call in one or more of the threads operates with non-initialized values.

The error in question occured by using OpenCV combined with TBB. Compiler is VS 2010. cv::log() is called on an array of Mat1f within a TBB parallel_for loop.

I did not check which functions other than log() use static variables.

The solution is simple: Get rid of static state of these const variables. In fact, the usage of static here gives no real speed benefit and is a relic of old habits.


Associated revisions

Revision 1bb0c574
Added by Roman Donchenko almost 12 years ago

Merge pull request #2462 from ibtaylor:fix_deblurring_calcBlurriness_var_name_typo

History

Updated by Vadim Pisarevsky over 12 years ago

I do not see how the constant tables may affect multi-threaded applications. By definition, they should be initialized before you call cv::log etc. for the first time. If there is a reproducible bug with a particular OpenCV functions, please, submit the corresponding sample. We used cv::log and other such functions in multi-threaded apps for several years without any problems.

  • Status changed from Open to Cancelled

Also available in: Atom PDF