| 学习路线指引(点击解锁) | 知识定位 | 人群定位 |
|---|---|---|
| 🧡 Python实战微信订餐小程序 🧡 | 进阶级 | 本课程是python flask+微信小程序的完美结合,从项目搭建到腾讯云部署上线,打造一个全栈订餐系统。 |
| 💛Python量化交易实战💛 | 入门级 | 手把手带你打造一个易扩展、更安全、效率更高的量化交易系统 |
好久不见,马甲哥封闭居家半个月,记录之前遇到的一件小事。
ConcurrentDictionary绝大部分api都是线程安全且原子性的,
唯二的例外是接收工厂委托的api:AddOrUpdate、GetOrAdd,这两个api不是原子性的,需要引起重视。
All these operations are atomic and are thread-safe with regards to all other operations on the ConcurrentDictionary class. The only exceptions are the methods that accept a delegate, that is, AddOrUpdate and GetOrAdd.
之前有个同事就因为这个case背了一个P。
AddOrUpdate(TKey, TValue, Func valueFactory);
GetOrAdd(TKey key, Func valueFactory);
(注意,包括其他接收工厂委托的重载函数)
A: 还不是因为微软不相信你能写出健壮的业务代码