Opened 14 years ago

Closed 12 years ago

#2825 closed Bugs (wontfix)

class boost::detail::atomic_count assumes long == int

Reported by: pelee@… Owned by: Peter Dimov
Milestone: To Be Determined Component: smart_ptr
Version: Boost Release Branch Severity: Problem
Keywords: Cc:

Description

boost::detail::atomic_count (as defined in atomic_count_gcc_x86.hpp, at least), has a member variable value_ that is of type int, yet the class constructor and operators use type long. When building for 64 bit targets on MacOS 10.5 and other LP64 architectures, long is 64 bits, while int is 32, leading to silent truncation if a 64 bit value were used to construct an atomic_count. Changing all of the signatures to use int instead of long solves this problem. It would probably be even safer to replace all the ints with boost::int32_t, assuming that the atomic operations being used really require 32 bit integers.

    explicit atomic_count( int v ) : value_( v ) {}

    void operator++()
    {
        __asm__
        (
            "lock\n\t"
            "incl %0":
            "+m"( value_ ): // output (%0)
            : // inputs
            "cc" // clobbers
        );
    }

    int operator--()
    {
        return atomic_exchange_and_add( &value_, -1 ) - 1;
    }

    operator int() const
    {
        return atomic_exchange_and_add( &value_, 0 );
    }

Change History (2)

comment:1 by Peter Dimov, 13 years ago

Milestone: Boost 1.39.0To Be Determined

comment:2 by Peter Dimov, 12 years ago

Resolution: wontfix
Status: newclosed
Note: See TracTickets for help on using tickets.