Specific question, short answer: YES.
You can check the implementation details of cv :: Mat in core/src/matrix.cppandinclude/.../core/core.hpp
Some snippets of code from OpenCV sources:
if( refcount )
CV_XADD(refcount, 1);
Where CV_XADD is the atomic test and increment.
inline void Mat::addref()
{ if( refcount ) CV_XADD(refcount, 1); }
inline void Mat::release()
{
if( refcount && CV_XADD(refcount, -1) == 1 )
deallocate();
data = datastart = dataend = datalimit = 0;
size.p[0] = 0;
refcount = 0;
}
Extra
Smart pointers offer a level of thread safety, but this does not mean that they are completely thread safe in every scenario. In particular, if you try to copy the general ptr, at the same time it will be destroyed by another thread, you will lose. This is not a mistake in implementation, but a constructive compromise between speed and utility.
All major general implementations of ptr (boost, stl) follow this approach.
source
share