2016-03-17 15:48:01 -0600 | received badge | ● Nice Question (source) |
2016-03-16 00:52:52 -0600 | received badge | ● Student (source) |
2016-03-15 16:56:50 -0600 | received badge | ● Editor (source) |
2016-03-15 13:26:12 -0600 | asked a question | Reentrancy problems Dear OpenCV, By executing the code on only one thread and not running the other two it runs fine, and when I run all three threads it 'sometimes' works too, but more often causes an assertion. Thanks. Upon examining this it appears that openCV is not re-entrant on initialization. Taking the cvtcolor function for example here is a snippet of code from BGR2HSV case: Here they attempt to do a one time initialization of the static tables, but what if thread 2 gets scheduled while thread 1 is processing this one time initialization? By building protection around my threads I am unable to observe the problem any further... So if I put a protection around the openCV code in my thread define oneTimeThreadInit as global initialized to false if ( myThread == THREAD1 ) || ( oneTimeThreadIniti == true ) ) { do my openCV code set oneTimeThreadInit = true } This is not exact code, as I'd use semaphores.... but the idea is if thread 1 is allowed to run to completion, to execute all my chosen openCV functions, this allows all my openCV functions to execute any one time initialization internally where they are using static vars... after this one time execution of all my chosen openCV functions, then I allow all threads to execute... since I've assured that the initialization is complete inside the openCV functions, I no longer am seeing the assertion error... So without exactly knowing where its conflicting... I believe this is the source of the problem. |