ReaderWriterLockSlim vs. Monitor

半世苍凉 提交于 2019-11-28 07:51:50

For write-only load the Monitor is cheaper than ReaderWriterLockSlim, however, if you simulate read + write load where read is much greater than write, then ReaderWriterLockSlim should out perform Monitor.

I'm no guru, but my guess is that RWLS is more geared towards heavy contention (e.g., hundreds of threads) whereas Monitor is more attuned towards those one-off synchronization issues.

Personally I use a TimerLock class that uses the Monitor.TryEnter with a timeout parameter.

How do you know what caused the bad performance? You can't go guessing it, the only way is to do some kind of profiling.

How do you handle locking for the parent collection or is it constant?

Maybe you need to add some debug output and see what really happens?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!