8

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 ?

dsolimano
  • 8,870
  • 3
  • 48
  • 63
Xaqron
  • 29,931
  • 42
  • 140
  • 205

2 Answers2

4

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.

Josh
  • 570
  • 6
  • 18
0

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.

Marc Vitalis
  • 2,129
  • 4
  • 24
  • 36