使用线程和非阻塞同步时需要注意哪些编译器、CLR 或 CPU 优化?
正如标题所述,在使用线程和非阻塞同步时需要注意哪些编译器、CLR 或 CPU 优化?
我读过一些关于指令重新排序以提高可能破坏事物的效率的内容,以及缓存优化将导致变量立即对其他线程不可见的内容 [0],但是还有其他我需要注意的(我确定有)吗?
任何推荐阅读/博客/文章/等的链接将不胜感激。
谢谢,埃吉尔。
更新:感谢 Jons 链接到 Joe Duffy 的博客文章,我发现了更多很棒的信息,我想我会与你们分享:
- 许多人指出的主要文章是 了解多线程应用中低锁定技术的影响,作者:Vance Morrison。
- 每个开发人员必须了解的多线程应用知识,同样由 Vance Morrison 撰写,对于我们这些不每天涉足多线程应用程序的人来说,这是一个非常好的新鲜事。
- Joe Duffy 的9 可重用并行数据结构和算法也是一本很好的读物。
- Jeffrey Richter 在他的 并发事务专栏 Performance-Conscious Thread Synchronization< 中提供了更多相同内容/a>.他对 SpinWaitLock 的实现非常好。
- 一般来说,MSDN 上的 并发事务专栏杂志非常值得推荐。
As the title says, what are the compiler, CLR or CPU optimizations to be aware of when working with threads and non-blocking synchronization?
I have read a little about the reordering of instructions to improve efficiency that could break things, and caching optimizations that will result in variables not being visible to other threads right away [0], but are there other (I sure there are) that I need to be aware of?
Any links to recommended reading/blogs/articles/etc will be much appreciated.
Thanks, Egil.
Update: Thanks to Jons link to Joe Duffy's blog post I found a lot more great information that I thought I would share with you guys:
- The primary article that many point to is Understand the Impact of Low-Lock Techniques in Multithreaded Apps by Vance Morrison.
- What Every Dev Must Know About Multithreaded Apps, also by Vance Morrison, is a very good fresher up for those of us who do not dabble in multithreaded applications daily.
- Joe Duffy's 9 Reusable Parallel Data Structures and Algorithms is also a great read.
- More of the same from Jeffrey Richter in his Concurrent Affairs column Performance-Conscious Thread Synchronization. His implementation of a SpinWaitLock is pretty nice.
- In general, the Concurrency Affairs columns over at MSDN Magazine are very recommendable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基本上,您需要了解 .NET 内存模型。忽略当前执行的优化 - 模型代码。
我推荐 Joe Duffy 的 这篇博文起点。
我还建议您不要推出自己的无锁代码。在我看来,这对凡人来说太难了。使用并行扩展(.NET 4.0 中)等框架,它可以为您做正确的事情。
You need to know about the .NET memory model, basically. Ignore what optimisations are currently performed - code to the model.
I would recommend this blog post by Joe Duffy as a good starting point.
I'd also recommend that you don't roll your own lock-free code. It's simply too hard for mortals, IMO. Use frameworks like Parallel Extensions (in .NET 4.0) which do the right thing for you.
Joe Duffy 有一本很棒的书,名为“Windows 上的并发编程”,我绝对相信如果您对 Windows 上的并发性(包括无锁编程)感兴趣,建议您阅读。
Joe Duffy has an excellent book called "Concurrent Programming on Windows" that I definitely recommend reading if you're interested in concurrency on Windows (including lock free programming).