The C# Memory Model in Theory and Practice

Best Practices
  • All code you write should rely only on the guarantees made by the ECMA C# specification, and not on any of the implementation details explained in this article.
  • Avoid unnecessary use of volatile fields. Most of the time, locks or concurrent collections (System.Collections.Concurrent.*) are more appropriate for exchanging data between threads. In some cases, volatile fields can be used to optimize concurrent code, but you should use performance measurements to validate that the benefit outweighs the extra complexity.
  • Instead of implementing the lazy initialization pattern yourself using a volatile field, use the System.Lazy<T> and System.Threading.LazyInitializer types.
  • Avoid polling loops. Often, you can use a BlockingCollection<T>, Monitor.Wait/Pulse, events or asynchronous programming instead of a polling loop.
  • Whenever possible, use the standard .NET concurrency primitives instead of implementing equivalent functionality yourself.

最新文章

  1. (转)RVA-相对虚拟地址解释
  2. HDU 5651 计算回文串个数问题(有重复的全排列、乘法逆元、费马小定理)
  3. SQL 常见函数使用
  4. java 关键字 transient
  5. Linux/Unix笔记本
  6. 【CITE】C#入门学习-----简单画图程序
  7. Steam和Byte[]之间进行输换
  8. java编程思想第四版中 net.mindview.util包
  9. PL/SQL 如何导出INSERT语句
  10. erl0005 - mnesia 分布式部署
  11. Seven Python Tools All Data Scientists Should Know How to Use
  12. 报错java.net.SocketException: Software caused connection abort: recv failed 怎么办
  13. SSRS 请求并显示SharePoint人员和组字段
  14. npm 常用命令详解[转]
  15. Javascript面向对象研究心得
  16. Android的JunitTest
  17. 使用charles抓取htpps的方法
  18. Centos6.8 安装tomcat8.5.11
  19. SpringBoot 整合Ehcache3
  20. 计算机信息系统安全保护等级划分准则(GB 17859-1999)

热门文章

  1. JS-排序详解-快速排序
  2. SQLserver 字符串转换日期,日期转换成为字符串
  3. c#基础在winform操作数据库,实现增删改查
  4. HTML5开发学习:本地存储Web Sql Database
  5. 【熊掌号mip插件】织梦DEDECMS百度熊掌号mip改造教程
  6. exce中42093和日期之间的关系
  7. spring和springMVC的面试问题总结
  8. [原创]Network Emulator for Windows Toolkit使用介绍
  9. reveal 使用注意事项
  10. java并发之如何解决线程安全问题