core(TLS): force TlsAbstraction initialization before main()#20802
core(TLS): force TlsAbstraction initialization before main()#20802opencv-pushbot merged 1 commit intoopencv:3.4from
Conversation
modules/core/src/system.cpp
Outdated
| #endif // CV_USE_FLS | ||
| #endif // _WIN32 | ||
|
|
||
| static TlsAbstraction* g_force_initialization_of_TlsAbstraction = getTlsAbstraction(); |
There was a problem hiding this comment.
Why do this rather than fix the startup threading of getTlsAbstraction() If someone is going to code a fix for this issue, risk code change, and the testing...I suggest a better use of effort is to fix the actual start issue rather than a partial workaround for the startup issue.
And this code change only assists with making that function call before main(). It doesn't help with other static calls, lambdas, Windows DLLs and DllMain(), probably Linux shared libraries, etc.
There was a problem hiding this comment.
I would not add this code into the opencv project. The specific user that reported a specific problem in their specific project due to a specific race-condition should use this kind of code in their project. Not OpenCV itself.
https://en.cppreference.com/w/cpp/language/siof
This hack (which it seems you have already merged) doesn't work across compile units. This hack create yet another race condition. The race condition that existed before continues to exist. And now this hack creates yet another.
A reliable "fix" requires rethinking the TLS startup (and shutdown) behavior. The startup can likely be fixed in C++11. The shutdown is very difficult (maybe impossible) to fix without a "shutdown manager" which requires classes/objects requiring shutdown handling to formall register themselves with the shutdown manager.
|
👍 |
relates #20606