nareshmlx/opencv-pr huggingface dataset:
**File:** samples/semihosting/histogram/histogram.cpp
**Change Type:** added
**Context:** PR #20392: AArch64 semihosting

**Code Changes:**
```diff
@@ -0,0 +1,43 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html
+
+#include <opencv2/imgproc.hpp>
+#include <opencv2/imgcodecs.hpp>
+
+#include <cstdint>
+#include <array>
```

Review comment:
Yes. And the same for `norm.cpp` example.
**File:** samples/cpp/grabcut.cpp
**Change Type:** modified
**Context:** PR #20200: Updated grabcut example to show the background in a transparant way - Hey all, I was playing around with the Grabcut example (https://docs....

**Code Changes:**
```diff
@@ -107,12 +107,14 @@ void GCApplication::showImage() const
 
     Mat res;
     Mat binMask;
-    if( !isInitialized )
-        image->copyTo( res );
-    else
-    {
-        getBinMask( mask, binMask );
-        image->copyTo( res, binMask );
```

Review comment:
`black.setTo(Scalar::all(255), binMask)`
**File:** samples/cpp/grabcut.cpp
**Change Type:** modified
**Context:** PR #20200: Updated grabcut example to show the background in a transparant way - Hey all, I was playing around with the Grabcut example (https://docs....

**Code Changes:**
```diff
@@ -107,12 +107,14 @@ void GCApplication::showImage() const
 
     Mat res;
     Mat binMask;
-    if( !isInitialized )
-        image->copyTo( res );
-    else
-    {
-        getBinMask( mask, binMask );
-        image->copyTo( res, binMask );
```

Review comment:
Why do we call `image->copyTo( res );` twice?
**File:** samples/cpp/grabcut.cpp
**Change Type:** modified
**Context:** PR #20200: Updated grabcut example to show the background in a transparant way - Hey all, I was playing around with the Grabcut example (https://docs....

**Code Changes:**
```diff
@@ -107,12 +107,14 @@ void GCApplication::showImage() const
 
     Mat res;
     Mat binMask;
-    if( !isInitialized )
-        image->copyTo( res );
-    else
-    {
-        getBinMask( mask, binMask );
-        image->copyTo( res, binMask );
```

Review comment:
Great proposal, changed!
**File:** samples/cpp/grabcut.cpp
**Change Type:** modified
**Context:** PR #20200: Updated grabcut example to show the background in a transparant way - Hey all, I was playing around with the Grabcut example (https://docs....

**Code Changes:**
```diff
@@ -107,12 +107,14 @@ void GCApplication::showImage() const
 
     Mat res;
     Mat binMask;
-    if( !isInitialized )
-        image->copyTo( res );
-    else
-    {
-        getBinMask( mask, binMask );
-        image->copyTo( res, binMask );
```

Review comment:
Good question... Removed :)
**File:** modules/dnn/src/layers/not_implemented_layer.cpp
**Change Type:** added
**Context:** PR #20402: Fix TFImporter diagnostic mode segfault

**Code Changes:**
```diff
@@ -0,0 +1,194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+#include "../precomp.hpp"
+#include "../dnn_common.hpp"
+
+namespace cv { namespace dnn {
+CV__DNN_INLINE_NS_BEGIN
```

Review comment:
> `Ptr<Layer>(new` `makePtr` should be used instead (similar to `std::make_shared`)
**File:** modules/dnn/src/tensorflow/tf_importer.cpp
**Change Type:** modified
**Context:** PR #20402: Fix TFImporter diagnostic mode segfault

**Code Changes:**
```diff
@@ -466,13 +466,16 @@ void ExcludeLayer(tensorflow::GraphDef& net, const int layer_index, const int in
         net.mutable_node()->DeleteSubrange(layer_index, 1);
 }
 
+class LayerHandler;
+
 class TFImporter
 {
 public:
     TFImporter(Net& net, const char *model, const char *config = NULL);
```

Review comment:
We have other importers too with similar problems. What would happen with multiple registration attempts? IMHO, register should go into `NotImplemented` as static method.
**File:** modules/dnn/test/test_tf_importer.cpp
**Change Type:** modified
**Context:** PR #20402: Fix TFImporter diagnostic mode segfault

**Code Changes:**
```diff
@@ -568,6 +568,39 @@ TEST_P(Test_TensorFlow_layers, l2_normalize_3d)
     runTensorFlowNet("l2_normalize_3d");
 }
 
+class Test_TensorFlow_diagnostics : public DNNTestLayer {
+public:
+    Test_TensorFlow_diagnostics()
+    {
+        enableModelDiagnostics(true);
+    }
```

Review comment:
is it used? should we restore log level in destructor?
**File:** modules/dnn/test/test_tf_importer.cpp
**Change Type:** modified
**Context:** PR #20402: Fix TFImporter diagnostic mode segfault

**Code Changes:**
```diff
@@ -568,6 +568,39 @@ TEST_P(Test_TensorFlow_layers, l2_normalize_3d)
     runTensorFlowNet("l2_normalize_3d");
 }
 
+class Test_TensorFlow_diagnostics : public DNNTestLayer {
+public:
+    Test_TensorFlow_diagnostics()
+    {
+        enableModelDiagnostics(true);
+    }
```

Review comment:
I deleted it already. Originally, yes, in constructor I was silencing logs and in the destructor the appropriate level was restored, but in event of test failure we would loose logs. Report.xml shouldn't contain stderr output and I decided to leave logs be.
**File:** modules/dnn/src/dnn_common.hpp
**Change Type:** modified
**Context:** PR #20402: Fix TFImporter diagnostic mode segfault

**Code Changes:**
```diff
@@ -15,6 +15,15 @@ void initializeLayerFactory();
 
 namespace detail {
 
+class NotImplemented : public Layer
+{
+public:
+    static Ptr<Layer> create(const LayerParams &params);
+
+    static void Register();
```

Review comment:
we don't need that in `dnn_common.hpp` anymore. Implementation can be placed near `NotImplemented::Register()`
**File:** modules/dnn/src/dnn_common.hpp
**Change Type:** modified
**Context:** PR #20402: Fix TFImporter diagnostic mode segfault
**Review Line:** 24

**Code Changes:**
```diff
+{
+public:
+    static Ptr<Layer> create(const LayerParams &params);
+
+    static void Register();
+    static void unRegister();
+};
+
 struct NetImplBase
 {
     const int networkId;  // network global identifier
```

Review comment:
Register -> register https://github.com/opencv/opencv/wiki/Coding_Style_Guide#naming-conventions
**File:** modules/dnn/src/layers/not_implemented_layer.cpp
**Change Type:** added
**Context:** PR #20402: Fix TFImporter diagnostic mode segfault

**Code Changes:**
```diff
@@ -0,0 +1,194 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+#include "../precomp.hpp"
+#include "../dnn_common.hpp"
+
+namespace cv { namespace dnn {
+CV__DNN_INLINE_NS_BEGIN
```

Review comment:
`CV_Error()` doesn't return (it throws or `abort()`). It is properly marked as `[[noreturn]]` for popular compilers. All statements below should be removed.
**File:** modules/dnn/src/dnn_common.hpp
**Change Type:** modified
**Context:** PR #20402: Fix TFImporter diagnostic mode segfault
**Review Line:** 24

**Code Changes:**
```diff
+{
+public:
+    static Ptr<Layer> create(const LayerParams &params);
+
+    static void Register();
+    static void unRegister();
+};
+
 struct NetImplBase
 {
     const int networkId;  // network global identifier
```

Review comment:
This is a reserved keyword.
**File:** modules/dnn/src/dnn_common.hpp
**Change Type:** modified
**Context:** PR #20402: Fix TFImporter diagnostic mode segfault

**Code Changes:**
```diff
@@ -15,6 +15,15 @@ void initializeLayerFactory();
 
 namespace detail {
 
+class NotImplemented : public Layer
+{
+public:
+    static Ptr<Layer> create(const LayerParams &params);
+
+    static void Register();
```

Review comment:
It is used in TFimporter::parseNode.
**File:** modules/dnn/src/dnn_common.hpp
**Change Type:** modified
**Context:** PR #20402: Fix TFImporter diagnostic mode segfault

**Code Changes:**
```diff
@@ -15,6 +15,15 @@ void initializeLayerFactory();
 
 namespace detail {
 
+class NotImplemented : public Layer
+{
+public:
+    static Ptr<Layer> create(const LayerParams &params);
+
+    static void Register();
```

Review comment:
Why is not `NotImplemented::Register()`? (or nothing because it is handled in `enableModelDiagnostics()`)
**File:** modules/dnn/src/dnn_common.hpp
**Change Type:** modified
**Context:** PR #20402: Fix TFImporter diagnostic mode segfault

**Code Changes:**
```diff
@@ -15,6 +15,15 @@ void initializeLayerFactory();
 
 namespace detail {
 
+class NotImplemented : public Layer
+{
+public:
+    static Ptr<Layer> create(const LayerParams &params);
+
+    static void Register();
```

Review comment:
Let's imagine TFImporter doesn't know some layer. It will be registered in order to not flood the output with errors about it.
**File:** modules/dnn/src/dnn_common.hpp
**Change Type:** modified
**Context:** PR #20402: Fix TFImporter diagnostic mode segfault

**Code Changes:**
```diff
@@ -15,6 +15,15 @@ void initializeLayerFactory();
 
 namespace detail {
 
+class NotImplemented : public Layer
+{
+public:
+    static Ptr<Layer> create(const LayerParams &params);
+
+    static void Register();
```

Review comment:
If diagnostic mode is not enabled then strategy must be "fail fast". We should not eat problems.
**File:** modules/dnn/src/dnn_common.hpp
**Change Type:** modified
**Context:** PR #20402: Fix TFImporter diagnostic mode segfault

**Code Changes:**
```diff
@@ -15,6 +15,15 @@ void initializeLayerFactory();
 
 namespace detail {
 
+class NotImplemented : public Layer
+{
+public:
+    static Ptr<Layer> create(const LayerParams &params);
+
+    static void Register();
```

Review comment:
I am indeed talking about the behavior of this function with diagnostic mode turned on.
**File:** modules/dnn/src/dnn_common.hpp
**Change Type:** modified
**Context:** PR #20402: Fix TFImporter diagnostic mode segfault

**Code Changes:**
```diff
@@ -15,6 +15,15 @@ void initializeLayerFactory();
 
 namespace detail {
 
+class NotImplemented : public Layer
+{
+public:
+    static Ptr<Layer> create(const LayerParams &params);
+
+    static void Register();
```

Review comment:
Got it. It is registered under a **new name**. There is another problem: - "NotImplemented" is unregistered when we call `enableModelDiagnostics(false);` - these unknown layers don't. Perhaps we should disallow turning off diagnostic mode if it is already enabled. This would be OK for tool, but this would cause problems with tests. --- BTW, `NotImplemented::Register()` can accept the "name" string parameter.
**File:** modules/dnn/src/dnn_common.hpp
**Change Type:** modified
**Context:** PR #20402: Fix TFImporter diagnostic mode segfault

**Code Changes:**
```diff
@@ -15,6 +15,15 @@ void initializeLayerFactory();
 
 namespace detail {
 
+class NotImplemented : public Layer
+{
+public:
+    static Ptr<Layer> create(const LayerParams &params);
+
+    static void Register();
```

Review comment:
The last problem can be resolved through singleton for registered `NotImplemented` layers. It should provide two methods: - `registerLayerType(const std::string& name)` - register and save used name - `unregisterLayerTypes()` (called by `enableModelDiagnostics(false)`) - cleanup all previously registered layer's types saved on registration
**File:** modules/dnn/src/dnn_common.hpp
**Change Type:** modified
**Context:** PR #20402: Fix TFImporter diagnostic mode segfault

**Code Changes:**
```diff
@@ -15,6 +15,15 @@ void initializeLayerFactory();
 
 namespace detail {
 
+class NotImplemented : public Layer
+{
+public:
+    static Ptr<Layer> create(const LayerParams &params);
+
+    static void Register();
```

Review comment:
I will push changes in a few hours. I added LayerHandler class which manages these layers and doesn't need to call registerLayer.
**File:** CMakeLists.txt
**Change Type:** modified
**Context:** PR #19985: [build][option] Introduce `OPENCV_DISABLE_THREAD_SUPPORT` option.

**Code Changes:**
```diff
@@ -512,6 +512,7 @@ OCV_OPTION(OPENCV_GENERATE_SETUPVARS  "Generate setup_vars* scripts" ON IF (NOT
 OCV_OPTION(ENABLE_CONFIG_VERIFICATION "Fail build if actual configuration doesn't match requested (WITH_XXX != HAVE_XXX)" OFF)
 OCV_OPTION(OPENCV_ENABLE_MEMALIGN     "Enable posix_memalign or memalign usage" ON)
 OCV_OPTION(OPENCV_DISABLE_FILESYSTEM_SUPPORT "Disable filesystem support" OFF)
+OCV_OPTION(OPENCV_DISABLE_THREAD_SUPPORT "Build the library without multi-threaded code." OFF)
 
 OCV_OPTION(ENABLE_PYLINT              "Add target with Pylint checks"                            (BUILD_DOCS OR BUILD_EXAMPLES) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) )
 OCV_OPTION(ENABLE_FLAKE8              "Add target with Python flake8 checker"                    (BUILD_DOCS OR BUILD_EXAMPLES) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) )
@@ -666,6 +667,11 @@ if(UNIX)
     set(HAVE_PTHREAD 1)
```

Review comment:
`OPENCV_DISABLE_THREAD_SUPPORT` ? (similar to `OPENCV_DISABLE_FILESYSTEM_SUPPORT`)
**File:** CMakeLists.txt
**Change Type:** modified
**Context:** PR #19985: [build][option] Introduce `OPENCV_DISABLE_THREAD_SUPPORT` option.

**Code Changes:**
```diff
@@ -512,6 +512,7 @@ OCV_OPTION(OPENCV_GENERATE_SETUPVARS  "Generate setup_vars* scripts" ON IF (NOT
 OCV_OPTION(ENABLE_CONFIG_VERIFICATION "Fail build if actual configuration doesn't match requested (WITH_XXX != HAVE_XXX)" OFF)
 OCV_OPTION(OPENCV_ENABLE_MEMALIGN     "Enable posix_memalign or memalign usage" ON)
 OCV_OPTION(OPENCV_DISABLE_FILESYSTEM_SUPPORT "Disable filesystem support" OFF)
+OCV_OPTION(OPENCV_DISABLE_THREAD_SUPPORT "Build the library without multi-threaded code." OFF)
 
 OCV_OPTION(ENABLE_PYLINT              "Add target with Pylint checks"                            (BUILD_DOCS OR BUILD_EXAMPLES) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) )
 OCV_OPTION(ENABLE_FLAKE8              "Add target with Python flake8 checker"                    (BUILD_DOCS OR BUILD_EXAMPLES) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) )
@@ -666,6 +667,11 @@ if(UNIX)
     set(HAVE_PTHREAD 1)
```

Review comment:
I believe root CMake file should not know details of `ts` module. Please move this into `modules/ts/CMakeLists.txt`, use ``` ocv_target_compile_definitions(${the_module} PUBLIC GTEST_HAS_PTHREAD=0) ``` instead.
**File:** 3rdparty/libwebp/CMakeLists.txt
**Change Type:** modified
**Context:** PR #19985: [build][option] Introduce `OPENCV_DISABLE_THREAD_SUPPORT` option.

**Code Changes:**
```diff
@@ -32,7 +32,9 @@ endif()
 #         Define the library target:
 # ----------------------------------------------------------------------------------
 
-add_definitions(-DWEBP_USE_THREAD)
+if(NOT OPENCV_DISABLE_THREAD_SUPPORT)
+  add_definitions(-DWEBP_USE_THREAD)
+endif()
 
 add_library(${WEBP_LIBRARY} STATIC ${OPENCV_3RDPARTY_EXCLUDE_FROM_ALL} ${lib_srcs} ${lib_hdrs})
```

Review comment:
`if(` without space.
**File:** modules/core/CMakeLists.txt
**Change Type:** modified
**Context:** PR #19985: [build][option] Introduce `OPENCV_DISABLE_THREAD_SUPPORT` option.

**Code Changes:**
```diff
@@ -153,6 +153,10 @@ if(OPENCV_CORE_EXCLUDE_C_API)
   ocv_target_compile_definitions(${the_module} PRIVATE "OPENCV_EXCLUDE_C_API=1")
 endif()
 
+if(OPENCV_DISABLE_THREAD_SUPPORT)
+  ocv_target_compile_definitions(${the_module} PUBLIC "OPENCV_DISABLE_THREAD_SUPPORT=1")
+endif()
+
 if(HAVE_HPX)
   ocv_target_link_libraries(${the_module} LINK_PRIVATE "${HPX_LIBRARIES}")
```

Review comment:
global `add_definition` should be enough.
**File:** modules/core/src/utils/logtagmanager.hpp
**Change Type:** modified
**Context:** PR #19985: [build][option] Introduce `OPENCV_DISABLE_THREAD_SUPPORT` option.
**Review Line:** 41

**Code Changes:**
```diff
     // to call LogTagManger (to prevent iterator invalidation), which needs enforced
     // with a non-recursive mutex.
-    using MutexType = std::mutex;
-    using LockType = std::lock_guard<MutexType>;
+    using MutexType = cv::Mutex;
+    using LockType = cv::AutoLock;
 
     enum class MatchingScope
     {
```

Review comment:
Perhaps we can use this branch only with `cv::` classes.
**File:** modules/core/include/opencv2/core/utility.hpp
**Change Type:** modified
**Context:** PR #19985: [build][option] Introduce `OPENCV_DISABLE_THREAD_SUPPORT` option.
**Review Line:** 717

**Code Changes:**
```diff
@@ -714,9 +714,27 @@ void Mat::forEach_impl(const Functor& operation) {
 /////////////////////////// Synchronization Primitives ///////////////////////////////
 
 #if !defined(_M_CEE)
+#ifndef OPENCV_DISABLE_THREAD_SUPPORT
 typedef std::recursive_mutex Mutex;
 typedef std::lock_guard<cv::Mutex> AutoLock;
-#endif
+#else // OPENCV_DISABLE_THREAD_SUPPORT
+// Custom (failing) implementation of `std::recursive_mutex`.
```

Review comment:
In general in makes sense (at least to catch typos through `-Wundef`) However, we don't use 0/1 "mandatory" values on macros with "_DISABLE_" prefix. Filesystem's macro name is `OPENCV_HAVE_FILESYSTEM_SUPPORT`. If you want to switch then it makes sense to rename the macro too (C++ related part only without changing CMake-specific names)
**File:** CMakeLists.txt
**Change Type:** modified
**Context:** PR #19985: [build][option] Introduce `OPENCV_DISABLE_THREAD_SUPPORT` option.

**Code Changes:**
```diff
@@ -512,6 +512,7 @@ OCV_OPTION(OPENCV_GENERATE_SETUPVARS  "Generate setup_vars* scripts" ON IF (NOT
 OCV_OPTION(ENABLE_CONFIG_VERIFICATION "Fail build if actual configuration doesn't match requested (WITH_XXX != HAVE_XXX)" OFF)
 OCV_OPTION(OPENCV_ENABLE_MEMALIGN     "Enable posix_memalign or memalign usage" ON)
 OCV_OPTION(OPENCV_DISABLE_FILESYSTEM_SUPPORT "Disable filesystem support" OFF)
+OCV_OPTION(OPENCV_DISABLE_THREAD_SUPPORT "Build the library without multi-threaded code." OFF)
 
 OCV_OPTION(ENABLE_PYLINT              "Add target with Pylint checks"                            (BUILD_DOCS OR BUILD_EXAMPLES) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) )
 OCV_OPTION(ENABLE_FLAKE8              "Add target with Python flake8 checker"                    (BUILD_DOCS OR BUILD_EXAMPLES) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) )
@@ -666,6 +667,11 @@ if(UNIX)
     set(HAVE_PTHREAD 1)
```

Review comment:
Why are there options are placed near python linter options group? Why is there extra spacing between them?
**File:** CMakeLists.txt
**Change Type:** modified
**Context:** PR #19985: [build][option] Introduce `OPENCV_DISABLE_THREAD_SUPPORT` option.

**Code Changes:**
```diff
@@ -512,6 +512,7 @@ OCV_OPTION(OPENCV_GENERATE_SETUPVARS  "Generate setup_vars* scripts" ON IF (NOT
 OCV_OPTION(ENABLE_CONFIG_VERIFICATION "Fail build if actual configuration doesn't match requested (WITH_XXX != HAVE_XXX)" OFF)
 OCV_OPTION(OPENCV_ENABLE_MEMALIGN     "Enable posix_memalign or memalign usage" ON)
 OCV_OPTION(OPENCV_DISABLE_FILESYSTEM_SUPPORT "Disable filesystem support" OFF)
+OCV_OPTION(OPENCV_DISABLE_THREAD_SUPPORT "Build the library without multi-threaded code." OFF)
 
 OCV_OPTION(ENABLE_PYLINT              "Add target with Pylint checks"                            (BUILD_DOCS OR BUILD_EXAMPLES) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) )
 OCV_OPTION(ENABLE_FLAKE8              "Add target with Python flake8 checker"                    (BUILD_DOCS OR BUILD_EXAMPLES) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) )
@@ -666,6 +667,11 @@ if(UNIX)
     set(HAVE_PTHREAD 1)
```

Review comment:
Comment about `GTEST_HAS_PTHREAD` is applicable for all these flags too. Root CMake script should not know implementation details of other modules or dependencies.
**File:** CMakeLists.txt
**Change Type:** modified
**Context:** PR #19985: [build][option] Introduce `OPENCV_DISABLE_THREAD_SUPPORT` option.

**Code Changes:**
```diff
@@ -512,6 +512,7 @@ OCV_OPTION(OPENCV_GENERATE_SETUPVARS  "Generate setup_vars* scripts" ON IF (NOT
 OCV_OPTION(ENABLE_CONFIG_VERIFICATION "Fail build if actual configuration doesn't match requested (WITH_XXX != HAVE_XXX)" OFF)
 OCV_OPTION(OPENCV_ENABLE_MEMALIGN     "Enable posix_memalign or memalign usage" ON)
 OCV_OPTION(OPENCV_DISABLE_FILESYSTEM_SUPPORT "Disable filesystem support" OFF)
+OCV_OPTION(OPENCV_DISABLE_THREAD_SUPPORT "Build the library without multi-threaded code." OFF)
 
 OCV_OPTION(ENABLE_PYLINT              "Add target with Pylint checks"                            (BUILD_DOCS OR BUILD_EXAMPLES) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) )
 OCV_OPTION(ENABLE_FLAKE8              "Add target with Python flake8 checker"                    (BUILD_DOCS OR BUILD_EXAMPLES) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) )
@@ -666,6 +667,11 @@ if(UNIX)
     set(HAVE_PTHREAD 1)
```

Review comment:
Why are these warnings should go into `getBuildInformation()`?
**File:** modules/core/src/async.cpp
**Change Type:** modified
**Context:** PR #19985: [build][option] Introduce `OPENCV_DISABLE_THREAD_SUPPORT` option.

**Code Changes:**
```diff
@@ -14,6 +14,7 @@
 #define CV_LOG_STRIP_LEVEL CV_LOG_LEVEL_DEBUG + 1
 #include <opencv2/core/utils/logger.hpp>
 
+#ifndef OPENCV_DISABLE_THREAD_SUPPORT
 
 #ifdef CV_CXX11
 #include <mutex>
@@ -236,6 +237,171 @@ struct AsyncArray::Impl
     }
```

Review comment:
"#else" non C++11 branch is candidate for removal. This patch forces to keep this. IMHO, we need dedicated implementation for `AsyncArray` for case without threads (or even forbid using of this).
**File:** modules/core/src/system.cpp
**Change Type:** modified
**Context:** PR #19985: [build][option] Introduce `OPENCV_DISABLE_THREAD_SUPPORT` option.

**Code Changes:**
```diff
@@ -216,7 +216,9 @@ std::wstring GetTempFileNameWinRT(std::wstring prefix)
 
 #endif
 #else
+#ifndef OPENCV_DISABLE_THREAD_SUPPORT
 #include <pthread.h>
+#endif
 #include <sys/time.h>
 #include <time.h>
 
```

Review comment:
destructors must not throw exceptions. Introduced changes about TLS should be minimized. Go on upper level, not need to "stub" local functions - work with public API only.
**File:** CMakeLists.txt
**Change Type:** modified
**Context:** PR #19985: [build][option] Introduce `OPENCV_DISABLE_THREAD_SUPPORT` option.

**Code Changes:**
```diff
@@ -512,6 +512,7 @@ OCV_OPTION(OPENCV_GENERATE_SETUPVARS  "Generate setup_vars* scripts" ON IF (NOT
 OCV_OPTION(ENABLE_CONFIG_VERIFICATION "Fail build if actual configuration doesn't match requested (WITH_XXX != HAVE_XXX)" OFF)
 OCV_OPTION(OPENCV_ENABLE_MEMALIGN     "Enable posix_memalign or memalign usage" ON)
 OCV_OPTION(OPENCV_DISABLE_FILESYSTEM_SUPPORT "Disable filesystem support" OFF)
+OCV_OPTION(OPENCV_DISABLE_THREAD_SUPPORT "Build the library without multi-threaded code." OFF)
 
 OCV_OPTION(ENABLE_PYLINT              "Add target with Pylint checks"                            (BUILD_DOCS OR BUILD_EXAMPLES) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) )
 OCV_OPTION(ENABLE_FLAKE8              "Add target with Python flake8 checker"                    (BUILD_DOCS OR BUILD_EXAMPLES) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) )
@@ -666,6 +667,11 @@ if(UNIX)
     set(HAVE_PTHREAD 1)
```

Review comment:
> Why are there options are placed near python linter options group? No meaningful reason for this. Please let me know where to move them. Do you want me to move the FILESYSTEM one in a separate patch? > Why is there extra spacing between them? Again, no reason for this :). I will remove the extra space after moving.