From 2eb7bf4cfa464f704be1f2f93cd056648b4853a4 Mon Sep 17 00:00:00 2001 From: Alexander Duda Date: Wed, 30 Nov 2022 11:37:35 +0100 Subject: [PATCH 1/2] core: improve doc for setNumThreads The old documentation implies that the call is only valid for the next parallel region and must be called again if addtional regions should be affected as well. --- modules/core/include/opencv2/core/utility.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/include/opencv2/core/utility.hpp b/modules/core/include/opencv2/core/utility.hpp index 108c0d93e7..5fc5a4eaac 100644 --- a/modules/core/include/opencv2/core/utility.hpp +++ b/modules/core/include/opencv2/core/utility.hpp @@ -179,7 +179,7 @@ CV_EXPORTS ErrorCallback redirectError( ErrorCallback errCallback, void* userdat CV_EXPORTS String tempfile( const char* suffix = 0); CV_EXPORTS void glob(String pattern, std::vector& result, bool recursive = false); -/** @brief OpenCV will try to set the number of threads for the next parallel region. +/** @brief OpenCV will try to set the number of threads for subsequent parallel regions. If threads == 0, OpenCV will disable threading optimizations and run all it's functions sequentially. Passing threads \< 0 will reset threads number to system default. This function must From 3bcc3e70f197fefdf6a36c7561297244b189a946 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Fri, 7 Apr 2023 13:56:57 +0300 Subject: [PATCH 2/2] Extended setNumThreads documentation according to code review. --- modules/core/include/opencv2/core/utility.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/core/include/opencv2/core/utility.hpp b/modules/core/include/opencv2/core/utility.hpp index 5fc5a4eaac..db8c42976f 100644 --- a/modules/core/include/opencv2/core/utility.hpp +++ b/modules/core/include/opencv2/core/utility.hpp @@ -181,9 +181,9 @@ CV_EXPORTS void glob(String pattern, std::vector& result, bool recursive /** @brief OpenCV will try to set the number of threads for subsequent parallel regions. -If threads == 0, OpenCV will disable threading optimizations and run all it's functions -sequentially. Passing threads \< 0 will reset threads number to system default. This function must -be called outside of parallel region. +If threads == 1, OpenCV will disable threading optimizations and run all it's functions +sequentially. Passing threads \< 0 will reset threads number to system default. +The function is not thread-safe. It must not be called in parallel region or concurrent threads. OpenCV will try to run its functions with specified threads number, but some behaviour differs from framework: