Comments on: Concurrency and lock-free basics I'm not totally agree with Kevin. Your assumption is right in the general case, and many programmers may avoid to build their own lock free algorithms, because it's VERY related to hardware and you have to perfectly know the hardware. BUT, this is a "game programming" oriented blog. I really dislike when a programmer in my team said "oh you should be careful with this, don't do it because I read somewhere "Never write your own lock-free code". If you're a low level engine programmer on console, sometimes you need to build your own stuff. If you're afraid to try, then you miss something. You certainly will fail at your first attempt and write buggy code. But when you understand why and when you fix it, you learn so much things! So if you're generalist programmer, and you don't need bloody speed routines, then DONT waste your time writing lock less code. But, if you're a low level programmer, try it, read the hardware doc, read the hardware bugs notes. You will learn so much stuff. I’m not totally agree with Kevin. Your assumption is right in the general case, and many programmers may avoid to build their own lock free algorithms, because it’s VERY related to hardware and you have to perfectly know the hardware.

BUT, this is a “game programming” oriented blog. I really dislike when a programmer in my team said “oh you should be careful with this, don’t do it because I read somewhere “Never write your own lock-free code”. If you’re a low level engine programmer on console, sometimes you need to build your own stuff. If you’re afraid to try, then you miss something. You certainly will fail at your first attempt and write buggy code. But when you understand why and when you fix it, you learn so much things!

So if you’re generalist programmer, and you don’t need bloody speed routines, then DONT waste your time writing lock less code.
But, if you’re a low level programmer, try it, read the hardware doc, read the hardware bugs notes. You will learn so much stuff.

]]>
By: Mattias Jansson /2011/06/20/concurrency-and-lock-free-basics/#comment-6092 Mattias Jansson  Tue, 21 Jun 2011 04:59:26 +0000 @Kevin: I absolutely agree! Leave it to the platform SDK people if at all possible. Barring that, Try to keep you access patterns simple - avoid having general many-way contention for the protected resources. Getting lock-free done right is about more than just about covering all code-flow cases in <strong>your</strong> code. You also have to think about compile-time optimizations as well as processor-specific memory write behaviors across threads, cores, and whole processors. If you think you know what you're doing, be sure to go find out what <a href="http://msdn.microsoft.com/en-us/library/ee418650.aspx" rel="nofollow">Bruce Dawson</a> <a href="http://www.gdcvault.com/play/1751/Lockless_Programming_in_Games" rel="nofollow">has to say on the topic</a>. My take away message was that I might get it right, but I'll never be 100% confident about it. @Kevin: I absolutely agree! Leave it to the platform SDK people if at all possible. Barring that, Try to keep you access patterns simple – avoid having general many-way contention for the protected resources.

Getting lock-free done right is about more than just about covering all code-flow cases in your code. You also have to think about compile-time optimizations as well as processor-specific memory write behaviors across threads, cores, and whole processors. If you think you know what you’re doing, be sure to go find out what Bruce Dawson has to say on the topic.

My take away message was that I might get it right, but I’ll never be 100% confident about it.

]]>
By: nicolas/2011/06/20/concurrency-and-lock-free-basics/#comment-6053 nicolas Mon, 20 Jun 2011 20:41:05 +0000 I'd prefer to see the disclaimer '<strong>Warning: Never write your own lock-free code. Seriously, even the experts mess it up</strong>.' at the bottom of this post, but that's just me. :D Good introduction! I’d prefer to see the disclaimer ‘Warning: Never write your own lock-free code. Seriously, even the experts mess it up.’ at the bottom of this post, but that’s just me. :D Good introduction!

]]>