Thread.Interlocked Question. Increment and Decrement returns?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Thread.Interlocked Question. Increment and Decrement returns?

  1. #1
    Tom Barnaby Guest

    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



  2. #2
    Mattias Sjögren Guest

    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

  3. #3
    Tom Barnaby Guest

    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center