I create a buffer manager through static member of BufferManager.CreateBufferManager
. This new created BufferManager
is used by multiple threads.
Should I use a lock
with TakeBuffer()
and ReturnBuffer()
or it is thread-safe by design ?
I create a buffer manager through static member of BufferManager.CreateBufferManager
. This new created BufferManager
is used by multiple threads.
Should I use a lock
with TakeBuffer()
and ReturnBuffer()
or it is thread-safe by design ?
Internally BufferManager.CreateBufferManager
returns an instance of WrappingBufferManager
which employs no form of concurrency control, but wraps multiple instances of SynchronizedPool<T>
which employ internal locking when Take()
ing a new buffer. So judging by the simplicity of the WrappingBufferManager
, it's safe to assume that any locking on your part would be redundant, and the returned class is in actual fact thread safe.
I experienced thread issues with BufferManager. I created a custom message encoder in WCF, and based on my observation, it's not always guaranteed that buffer manager gets created for each call. Therefore, bytes are being reused/returned by other threads, thus corrupting my data.
So, to answer your question... No they are NOT. Since you are reusing the same instance, they are not guaranteed thread-safe.