Repository: opencv
Issue: Segmentation fault on ParallelLoopBodyWrapperContext::finalize with ENABLE_INSTRUMENTATION=ON
Labels: bug

### System Information

OpenCV version: 4.9.0
Platform: Nvidia Jetson Orin Developer Kit 
Operating System: JetPack 5.1.2 - Ubuntu 20.04
Compiler & compiler version: GCC 9.4.0
Compilation line:
```bash
cmake -DCMAKE_VERBOSE_MAKEFILE=ON -DOPENCV_EXTRA_MODULES_PATH="$cv_contrib_pkg_path/modules"  \
-DCMAKE_BUILD_TYPE=Release -DBUILD_WITH_DEBUG_INFO=ON \
-DENABLE_PROFILING=ON -DENABLE_INSTRUMENTATION=ON \
-DOPENCV_ENABLE_MEMORY_SANITIZER=ON -DENABLE_BUILD_HARDENING=ON \
-DOPENCV_ENABLE_NONFREE=ON -DOPENCV_GENERATE_PKGCONFIG=ON -DOPENCV_LAPACK_FIND_PACKAGE_ONLY=OFF \
-DOpenGL_GL_PREFERENCE=GLVND -DINSTALL_TO_MANGLED_PATHS=ON -DWITH_EIGEN=ON -DWITH_LAPACK=ON \
-DWITH_CUDA=ON -DWITH_CUFFT=ON -DWITH_CUBLAS=ON -DWITH_CUDNN=ON -DWITH_VA=ON -DWITH_OPENCL=ON \
-DWITH_OPENCL_SVM=ON -DWITH_TBB=ON -DWITH_OPENMP=ON -DWITH_ITT=ON -DWITH_IMGCODEC_PXM=ON \
-DWITH_IMGCODEC_PFM=ON -DWITH_JPEG=ON -DWITH_PNG=ON -DWITH_TIFF=ON -DWITH_OPENEXR=ON \
-DWITH_GDAL=ON -DWITH_GDCM=ON -DWITH_JASPER=OFF -DWITH_V4L=ON -DWITH_FFMPEG=ON \
-DWITH_GSTREAMER=ON -DWITH_1394=ON -DWITH_PVAPI=OFF -DWITH_XINE=OFF -DWITH_GTK=ON -DWITH_VTK=ON \
-DWITH_QT=OFF -DWITH_FREETYPE=ON -DWITH_PROTOBUF=ON -DOPENCV_DNN_OPENCL=ON -DOPENCV_DNN_CUDA=ON \
-DWITH_VULKAN=ON -DWITH_TESSERACT=ON -DWITH_QUIRC=ON -DWITH_ADE=ON -DWITH_NGRAPH=OFF \
-DWITH_CLP=ON -DBUILD_opencv_python2=ON -DBUILD_opencv_python3=ON -DBUILD_opencv_dnn=ON \
-DBUILD_opencv_dnn_modern=ON -DBUILD_opencv_face=ON -DBUILD_JAVA=OFF -DBUILD_PROTOBUF=ON \
-DBUILD_EXAMPLES=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_TBB=ON -DBUILD_ITT=ON -DWITH_ARAVIS=ON \
-DWITH_UEYE=ON -DWITH_OPENNI2=ON -DWITH_LIBREALSENSE=ON -DWITH_CAROTENE=ON -DWITH_NVCUVID=OFF \
-DWITH_NVCUVENC=OFF -DWITH_OPENCLAMDFFT=OFF -DWITH_OPENCLAMDBLAS=OFF -DWITH_TENGINE=ON \
-DWITH_FLATBUFFERS=ON -DOPENCV_DNN_TFLITE=ON -S "$cv_pkg_path"
```

### Detailed description

A segmentation fault is thrown when the code uses a `parallel_for`.
First discovered debayering an image, and after, also appeared trying to rectify an image.
Looking at the backtrace shows that the error was [here](https://github.com/opencv/opencv/blob/4.9.0/modules/core/src/parallel.cpp#L227).
This made me suspicious about the `#ifdef ENABLE_INSTRUMENTATION`, witch I recently enabled on the compilation.
Using this compilation have also appeared runtime errors regarding the TLS which I previously managed by setting `LD_PRELOAD=libgomp.so.1` enviroment variable.

All of this made me try to disable the instrumentation, which has worked to remove the error for now.

### Steps to reproduce

In this case the code that ran the OpenCV instructions is from [here](https://github.com/ros-perception/image_pipeline/blob/noetic/image_proc/src/nodelets/debayer.cpp#L235) and [here](https://github.com/ros-perception/vision_opencv/blob/noetic/image_geometry/src/pinhole_camera_model.cpp#L541).

But a minimal example would be just:
```cpp
cv::Mat bayered_img, bgr_img;

bayered_img = <capture_bayered_image_from_camera>;

cv::cvtColor(bayered_img, bgr_img, cv::COLOR_BayerBG2BGR);
```

### 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
- [X] I updated to the latest OpenCV version and the issue is still there
- [x] There is reproducer code and related data files (videos, images, onnx, etc)