From bfd6ae77f53f72ca0be1d7cd0ac401a6f2b22ba7 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Thu, 14 Jul 2016 14:20:37 +0300 Subject: [PATCH] Add note that cv::cuda::Stream class is not thread safe --- modules/core/include/opencv2/core/cuda.hpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/modules/core/include/opencv2/core/cuda.hpp b/modules/core/include/opencv2/core/cuda.hpp index 64bc53ef51..96685513b1 100644 --- a/modules/core/include/opencv2/core/cuda.hpp +++ b/modules/core/include/opencv2/core/cuda.hpp @@ -447,7 +447,26 @@ CV_EXPORTS void unregisterPageLocked(Mat& m); functions use the constant GPU memory, and next call may update the memory before the previous one has been finished. But calling different operations asynchronously is safe because each operation has its own constant buffer. Memory copy/upload/download/set operations to the buffers you hold are -also safe. : +also safe. + +@note The Stream class is not thread-safe. Please use different Stream objects for different CPU threads. + +@code +void thread1() +{ + cv::cuda::Stream stream1; + cv::cuda::func1(..., stream1); +} + +void thread2() +{ + cv::cuda::Stream stream2; + cv::cuda::func2(..., stream2); +} +@endcode + +@note By default all CUDA routines are launched in Stream::Null() object, if the stream is not specified by user. +In multi-threading environment the stream objects must be passed explicitly (see previous note). */ class CV_EXPORTS Stream {