On Tuesday, November 13, 2012 14:22:07 Walter Bright wrote: > I'm just not convinced that having the compiler add memory barriers: > > 1. will result in correctly working code, when done by programmers who have > only an incomplete understanding of memory barriers, which would be about > 99.9% of us. > > 2. will result in efficient code
Being able to have double-checked locking work would be valuable, and having memory barriers would reduce race condition weirdness when locks aren't used properly, so I think that it would be desirable to have memory barriers. If there's a major performance penalty though, that might be a reason not to do it. Certainly, I don't think that there's any question that adding memory barriers won't make it so that you don't need mutexes or synchronized blocks or whatnot. shared's primary benefit is in logically separating normal code from code that must shared data across threads and making it possible for the compiler to optimize based on the fact that it knows that a variable is thread-local. - Jonathan M Davis
