小编Tra*_*isK的帖子

atomic addorupdate(尝试使用并发字典编写命名的locker)

ConcurrentDictionary陷阱 - 来自GetOrAdd和AddOrUpdate的委托工厂是否同步?注意到AddOrUpdate不是原子的(并且不能保证代理不会多次运行).

我想实现的名称使用并发字典一拉锁定实现这里,但如果字典不应该永远增长,就像这样:

public class ConcurrentDictionaryNamedLocker : INamedLocker
{
    // the IntObject values serve as the locks and the counter for how many RunWithLock jobs 
    // are about to enter or have entered the critical section.
    private readonly ConcurrentDictionary<string, IntObject> _lockDict = new ConcurrentDictionary<string, IntObject>();
    private static readonly IntObject One = new IntObject(1);
    private readonly Func<string, IntObject, IntObject> _decrementFunc = (s, o) => o - 1;
    private readonly Func<string, IntObject, IntObject> _incrementFunc = (s, o) => …
Run Code Online (Sandbox Code Playgroud)

.net concurrency concurrentdictionary

7
推荐指数
1
解决办法
916
查看次数

标签 统计

.net ×1

concurrency ×1

concurrentdictionary ×1