core: improve doc for setNumThreads#22889
Conversation
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.
| /** @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 |
There was a problem hiding this comment.
Proposed change looks good to me.
However there is another design issue. Which contradicts to the real implementation of some parallel backends.
There is mess with threads == 0 and threads == 1 values.
E.g., OpenMP case:
omp_set_num_threads(threads > 0 ? threads : numThreadsMax);
(code is from 2012 at least)
Docs states this:
If threads == 0, OpenCV will disable threading optimizations and run all it's functions sequentially
So, using '0' parameter value is not recommended at all and it is a subject to the change.
Another important note, setNumThreads() is not a thread-safe function.
It is fatal to call it simultaneously in case of TBB at least (TBB's arena may become corrupted).
|
@D-Alex Please add note on the thread-safety for |
|
@mshabunin I extended the patch according to Alexander's recommendation. Could you take a look? |
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.
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.