Repository: opencv
Issue: OpenCV stuck in getCoreTlsData
Labels: bug

### System Information

OpenCV version: 4.5.5
Operating System / Platform: Microsoft Windows 10 Enterprise 2016 LTSB
Precompiled OpenCV world dll

### Detailed description

We have a thread that is repeatedly calling BackgroundSubtractorMOG2::apply. After running for about 5 days it got stuck like below. I cannot reproduce this issue, but it has happened a few times now. I have a minidump available if needed.

getCoreTlsData calls ntdll!RtlpLowFragHeapAllocFromContext, and then WinDbg claims the current frame is ntdll!NtYieldExecution. There is some lazy initialization going on in getCoreTlsData, but as the process was already running for multiple days, I don't see how memory needs to be allocated. Is it a deadlock with some OS lock maybe (just guessing)?

```
Thread  30
TEB information is not available so a stack size of 0xFFFF is assumed
Current frame: ntdll!NtYieldExecution+0x14
Child-SP         RetAddr          Caller, Callee
000000dac803d680 00007ff8e0bd3b20 ntdll!RtlpAllocateHeapInternal+0x1090, calling ntdll!RtlpLowFragHeapAllocFromContext
000000dac803d6b0 00007ff896d807a9 *** WARNING: Unable to verify checksum for opencv_world455.dll
opencv_world455!cv::getCoreTlsData+0x9, calling opencv_world455!cv::getCoreTlsData+0x20
000000dac803d6e0 00007ff896d29b36 opencv_world455!cv::ocl::OpenCLExecutionContext::getCurrent+0x26, calling opencv_world455!cv::getCoreTlsData
000000dac803d730 00007ff896d2a01d opencv_world455!cv::ocl::Queue::getDefault+0x9d, calling opencv_world455!__security_check_cookie
000000dac803d9d0 00007ff896d35704 opencv_world455!cv::ocl::Kernel::Impl::run+0xb54, calling opencv_world455!__security_check_cookie
000000dac803da70 00007ff896d1f665 opencv_world455!cv::ocl::Kernel::Impl::cleanupUMats+0x135, calling opencv_world455!__security_check_cookie
000000dac803dbc0 00007ff896d1c57d opencv_world455!cv::ocl::Kernel::Impl::addUMat+0xed, calling opencv_world455!__security_check_cookie
000000dac803dc30 00007ff896d38e4f opencv_world455!cv::ocl::Kernel::set+0xe9f, calling opencv_world455!__security_check_cookie
000000dac803dca0 00007ff896d1f665 opencv_world455!cv::ocl::Kernel::Impl::cleanupUMats+0x135, calling opencv_world455!__security_check_cookie
000000dac803dcb0 00007ff896d84648 opencv_world455!cv::utils::trace::details::Region::Region+0x598, calling opencv_world455!__security_check_cookie
000000dac803dd60 00007ff896d35965 opencv_world455!cv::ocl::Kernel::run+0x245, calling opencv_world455!cv::ocl::Kernel::Impl::run
000000dac803df30 00007ff897620fe5 opencv_world455!cv::BackgroundSubtractorMOG2Impl::ocl_apply+0x455, calling opencv_world455!cv::ocl::Kernel::run
000000dac803e0d0 00007ff89761fc88 opencv_world455!cv::BackgroundSubtractorMOG2Impl::apply+0xb8, calling opencv_world455!cv::BackgroundSubtractorMOG2Impl::ocl_apply
```

### Steps to reproduce

I cannot reproduce this issue, but it has happened a few times now.

### Issue submission checklist

- [X] I report the issue, it's not a question
- [X] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- [ ] I updated to the latest OpenCV version and the issue is still there
- [ ] There is reproducer code and related data files (videos, images, onnx, etc)