What are the compiler, CLR or CPU optimizations to be aware of when working with threads and non-blocking synchronization?
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.
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 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).
精彩评论