Thread: Interlocked increment/decrement

  1. #16
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by Elysia View Post
    Lock-free smart pointer to increase the ref count is what I'm trying to do.
    The ref count can be 8, 16, 32 or 64 bits. Or that was the intention anyway.
    I know VS has a 64-bit interlocked increment, too, so it isn't impossible.
    You're either decades ahead of your time, or insane. 32 bits for a ref count should be enough for the next 20 years or so.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  2. #17
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I like being mad
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by matsp View Post
    Are you sure that it's meaningful to have more than 2^31 references to a pointer?
    Leaving aside design considerations, it's flat-out impossible. Under 32-bit addressing, you only have 4 gigabytes of RAM anyway. If the reference count was actually equal to 2^32-1, that would imply an equal number of references to an object, and since any such reference will be at least as large as a pointer, this would require 16 gigabytes to represent. But we don't have 16 gigabytes, as we already said we are using 32-bit addressing. Contradiction. QED.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. thread safety using Interlocked
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 05-16-2008, 03:07 AM
  2. Increment/Decrement operator troubles
    By LineOFire in forum C Programming
    Replies: 6
    Last Post: 11-15-2006, 10:28 PM
  3. increment/decrement operators
    By ZakkWylde969 in forum C++ Programming
    Replies: 10
    Last Post: 07-10-2003, 04:17 PM
  4. Increment/Decrement for loop?
    By --]bthNzA in forum C Programming
    Replies: 11
    Last Post: 12-29-2001, 01:10 AM