使用线程和非阻塞同步时需要注意哪些编译器、CLR 或 CPU 优化?

发布于 2024-08-13 16:59:11 字数 1233 浏览 10 评论 0原文

正如标题所述,在使用线程和非阻塞同步时需要注意哪些编译器、CLR 或 CPU 优化?

我读过一些关于指令重新排序以提高可能破坏事物的效率的内容,以及缓存优化将导致变量立即对其他线程不可见的内容 [0],但是还有其他我需要注意的(我确定有)吗?

任何推荐阅读/博客/文章/等的链接将不胜感激。

谢谢,埃吉尔。

更新:感谢 Jons 链接到 Joe Duffy 的博客文章,我发现了更多很棒的信息,我想我会与你们分享:

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:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时间你老了 2024-08-20 16:59:11

基本上,您需要了解 .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.

探春 2024-08-20 16:59:11

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文