Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need MemoryBarrier with ReaderWriterLockSlim?

It looks like the mono implementation has no MemoryBarrier calls inside the ReaderWriterLockSlim methods. So when I make any changes inside a write lock, I can receive old cached values in another thread which uses a read lock.

Is it really possible? Should I insert MemoryBarrier before and after the code inside Read and Write lock?

like image 539
Vlad Avatar asked Mar 22 '23 07:03

Vlad


1 Answers

Looking at (what I think is) the mono source, the Mono ReaderWriterLockSlim is implemented using Interlocked calls.

These calls include a memory barrier on x86, so you shouldn't need to add one.

like image 195
Peter Wishart Avatar answered Mar 31 '23 16:03

Peter Wishart