nareshmlx/opencv-pr huggingface dataset:
**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:
Just to make sure I don't miss anything: the only option that is left to be moved is `OPJ_USE_THREAD`, right? Also, am I correct in assuming that I can do the following in the openjpeg's CMakeList.txt? ``` if (OPENCV_DISABLE_THREAD_SUPPORT) set(OPJ_USE_THREAD OFF) endif() ``` (Put it in other words: is `OPENCV_DISABLE_THREAD_SUPPORT` visible in the cmake configuration of openjpg/?)
**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:
Yeah, they are here mostly because I was using them for debugging when I was developing this patch. I am happy to remove them, or to move them to a more appropriate place. Let me know what you prefer.
**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:
I am happy to provide an implementation of `AsyncArray` that does not use threads. I'll give it a go, but I might need some guidance on this. Just to make sure I am going in the right direction. You want me to have a big `#ifundef / #else / #endif` switch where the `#else` branch exposes the curret implementation (threaded) of `AsyncArray`, while the `#ifundef OPENCV_DISABLE_THREAD_SUPPORT` will implement AsyncArray without using threads (ro shoudl it be just stubs?). Also, what the alternative... > even forbid using of this ... consist of? Disabling the use of AsyncArray in all places where it is used?
**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. > Sure! Why? (Genuine question, I am not challenging your comment!) > Introduced changes about TLS should be minimized. > Go on upper level, not need to "stub" local functions - work with public API only. What does "go on upper level" mean? Leave `TlsAbstraction` unchanges, and use the `#ifundef / #else / #endif` in all places where `TlsAbstraction` is used?
**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:
It makes sense to move them (both) upper, right after `OPENCV_ENABLE_MEMALIGN`
**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:
Yes, this option should work. (please remove space after `if` and `bracket`)
**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:
Prefer to use CMake's `message(WARNING ..)`
**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:
Stub with exceptions should work for now (there are no many places which uses AsyncArray)
**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:
Main goal here is to minimize amount of `#if` conditions. Public API for TLS is `TLSDataContainer`. Other things (like `TlsAbstraction`, `TlsStorage`) are local implementation details - we should not care about them here. Stub `TLSDataContainer` with straightforward implementation.
**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:
In the same place? Or should I move it to a place where all warnings are?
**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'll mark this as done, the warnings are in the same place where the status messages were. Let me know if you want me to move them somewhere else.
**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:
Hum - `OPENCV_DISABLE_THREAD_SUPPORT` does not seem to be visible in the openjpeg folder. I get the following message when trying to build for baremetal after moving ` set(OPJ_USE_THREAD OFF)` in openjpeg: ``` /home/frapet01/projects/opencv/opencv/3rdparty/openjpeg/openjp2/thread.c: In function 'opj_thread_join': /home/frapet01/projects/opencv/opencv/3rdparty/openjpeg/openjp2/thread.c:423:5: warning: implicit declaration of function 'pthread_join'; did you mean 'opj_thread_join'? [-Wimplicit-function-declaration] 423 | pthread_join(thread->thread, &status); | ^~~~~~~~~~~~ | opj_thread_join ``` Would setting `set(OPJ_USE_THREAD OFF)` in the toolchain file of the baremetal platform OK? Or is there a more canonical way to do this?
**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:
I started providing stubs for the API of `cv::AsyncArray`, and it turned out I also need to provide stubs for `cv::AsyncPromise`. The approach I followed was to remove the `AsyncArray::Impl` definition and uses. This however caused writing many `#ifundef / #else / #endif` cases, which doesn't seem to fit very well with the goal of miniming such cases. Would it be OK if instead of providing stubs for `cv::AsyncArray` and `cv::AsyncPromise`, I would be providing a stub class `AsyncArray::Impl` that would expose stubs only for the methods used by `cv::AsyncArray` and `cv::AsyncPromise`? This solution would still provide useful exception message, and would require just a couple of `#ifundef / #else / #endif` cases.
**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:
Done. I'll move the FILESYSTEM one separately, though.
**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:
With the addition of #20137 , I consider this done.
**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 propose use FATAL message for the case, because `OPENCV_DISABLE_THREAD_SUPPORT` disables Mutex and other sync primitives and makes parallel implementations unsafe.
**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:
The option is not exported to `OpenCV-config.cmake` and other build configs. All methods in header files will use another pre-processor branch and break user code.
**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:
Please rollback `#ifdef CV_CXX11` => `#if defined(CV_CXX11)` unnecessary changes.
**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:
Revert this, handle `Impl` only if needed.
**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 am happy to do the export of the variable but I am not sure I understand the issue. Also, how can I export `OPENCV_DISABLE_THREAD_SUPPORT` in `OpenCV-config.cmake`? I have looked a bit into `cmake/OpenCVGenConfig.cmake` but I am missing the mechanism that does this export.
**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 do we need this? It should be handled in `cmake/vars/OPENCV_DISABLE_THREAD_SUPPORT.cmake`: https://github.com/opencv/opencv/pull/19985/files#diff-87b6de92e07d14f041e4b331f8936a5d5a4f2f8e499aa71bc3967de40cff9960 Please avoid any specific changes in root CMakeLists.txt - it should not manage details of 3rdparty components (otherwise we would get unsupportable huge mess) --- Ensure that you have clean CMake cache (after code update)
**File:** modules/features2d/src/sift.simd.hpp
**Change Type:** modified
**Context:** PR #20204: Improve SIFT for arm64/Apple silicon

**Code Changes:**
```diff
@@ -450,31 +450,184 @@ class findScaleSpaceExtremaT
             const sift_wt* currptr = img.ptr<sift_wt>(r);
             const sift_wt* prevptr = prev.ptr<sift_wt>(r);
             const sift_wt* nextptr = next.ptr<sift_wt>(r);
+            int c = SIFT_IMG_BORDER;
 
-            for( int c = SIFT_IMG_BORDER; c < cols-SIFT_IMG_BORDER; c++)
+#if CV_SIMD && !(DoG_TYPE_SHORT)
+            const int vecsize = v_float32::nlanes;
+            for( ; c <= cols-SIFT_IMG_BORDER - vecsize; c += vecsize)
```

Review comment:
I propose to use CV_SIMD128 macro to guard the changes. The patch may be relevant for other architectures, besides Intel and ARM.