我知道ConcurrentHashMap是线程安全的e.g.putIfAbsent,替换等等,但我想知道,下面的代码块是否安全?if (accumulator.containsKey(key)) { //accumulator is a ConcurrentHashMap} else {}
请记住,键的累加器值可能由两个不同的线程<
在我的课堂上,我加载了一些文件,为了提高效率,我想要一个线程安全的缓存。我在map类中看到有一个putIfAbsent方法,但它不接受async类型。也不确定这种结构在一般情况下是否安全使用。_cache.containsKey(name)) { if (!_cache.containsKey(name)) {
_cache[name] = await new File(name).readAsSt
线程下面的接近安全吗?我知道ConcurrentDictionary提供了TryRemove方法,但我只是不喜欢有一个我永远不会使用的值变量。ConcurrentDictionary<int, int> myDict = new ConcurrentDictionary<int, int>();
if (myDict.ContainsKey