Don't get me wrong; I'm not asking how to use the Interlocked class. I'm looking more for the decisions leading up other people's use of Interlocked.
Scott has a correct answer with the C# increment operator is not atomic and if called from multiple threads will result in random data. Same holds true for +=, -=, --, /=, *=, etc. But, he qualifies it with multiple threads. I've seen some pretty strange uses of Interlocked.Increment/InterlockedIncrement over the years and was curious of people's concept of the methods and the semantics. On Fri, 7 Apr 2006 14:06:31 -0400, Shawn Wildermuth <[EMAIL PROTECTED]> wrote: >Performance....they are a lot faster than a lock and much lighter weight. >THere is a great discussion of them in Jeffrey Richter's new book "CLR via >C#". I'd suggest picking that up. > > > > >Thanks, > >Shawn Wildermuth >http://adoguy.com >C# MVP, MCSD.NET, Author and Speaker > > >-----Original Message----- >From: Discussion of advanced .NET topics. >[mailto:[EMAIL PROTECTED] On Behalf Of Peter Ritchie >Sent: Friday, April 07, 2006 1:41 PM >To: [email protected] >Subject: [ADVANCED-DOTNET] Interlocked.Increment/Decrement/Add > >The topic of using Interlocked.Increment(Int32) came up elsewhere, and I was >wondering what other's in the community were doing with Interlocked in their >code and their coding guidelines. > >If you're using Interlocked.Increment(Int32), .Decrement(Int32), or .Add >(Int32, Int32), in particular, what are you expectations of these methods? >Why have you chosen them over equivalent language syntax? > >I'd also be interested on your thoughts on >Interlocked.Increment/Decrement/Add(Int64). Do you use the corresponding >Interlocked.Read(Int64) as well? =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com
