开发者

ConcurrentDictionary updates and enumeration thread sync

开发者 https://www.devze.com 2022-12-29 13:47 出处:网络
I have 1.N threads writing to a .net 4.0 Concurren开发者_C百科tDictionary. I have another thread which fires every 5 seconds (settable in app.config) to enumerate the dictionary, and potentially remov

I have 1.N threads writing to a .net 4.0 Concurren开发者_C百科tDictionary. I have another thread which fires every 5 seconds (settable in app.config) to enumerate the dictionary, and potentially remove some items. I want to halt the write operations during the enumeration.

What would be the best primitive to synchronize these two operations. Any help would be appreciated.

Bob.


use ReaderWriterLockSlim (http://msdn.microsoft.com/library/system.threading.readerwriterlockslim(VS.90).aspx) so enumerating thread will request exclusive lock and writing threads non-exclusive.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号