What are the compiler, CLR or CPU optimizations to be aware of when working with threads and non-blocking synchronization?

StackOverflow https://stackoverflow.com/questions/1848326

Question

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:

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top