-
Thread.Interlocked Question. Increment and Decrement returns?
The documentation is a little thin on the System.Threading.Interlocked class,
so I thought I would ask for some educated guesses here. The question is:
"What is the value that Increment and Decrement return?"
I first assumed that it simply returned the result of operation. Based on
the testing I've done, that is exactly what is happening. My test code depends
on the functions returning the resulting value, and it is working fine.
However I looked into the corresponding Win32 functions and read that they
return a negative value if the result is less than zero, zero if the result
is zero, and a positive value if the result is greater than zero. That's
a much broader definition than the assumption I'm making.
The .NET Beta doc is mute on this subject. So any educated guesses out there
based on experience with the Win32 API functions? Should I continue to assume
that the functions return the result of the operation?
Tom Barnaby
www.intertech-inc.com
-
Re: Thread.Interlocked Question. Increment and Decrement returns?
Tom,
>I first assumed that it simply returned the result of operation. Based on
>the testing I've done, that is exactly what is happening. My test code depends
>on the functions returning the resulting value, and it is working fine.
That's what it should return, according to the docs.
>However I looked into the corresponding Win32 functions and read that they
>return a negative value if the result is less than zero, zero if the result
>is zero, and a positive value if the result is greater than zero.
If you check MSDN, you'll see that the return value of
Interlocked[Inc|Dec]rement depends on the platform. What you said is
true for Windows 95. On NT4 and later versions, the return value is
indeed the correct value.
http://msdn.microsoft.com/library/ps...nchro_1k38.htm
Matt
====================================
Mattias Sjögren - mattias @ mvps.org
http://www.msjogren.net/dotnet/
CodeHound - The Software Developer's Search Engine
http://www.codehound.com
-
Re: Thread.Interlocked Question. Increment and Decrement returns?
mattias.dont.want.spam@mvps.org (Mattias Sjögren) wrote:
>Tom,
>
>>I first assumed that it simply returned the result of operation. Based
on
>>the testing I've done, that is exactly what is happening. My test code
depends
>>on the functions returning the resulting value, and it is working fine.
>
>That's what it should return, according to the docs.
>
>
Thanks. 2 minutes after posting the question, I found where it said this
explicitly in the docs. Guess I did not look too hard because I saw the
"to be supplied" comment next to the link.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks