
There is a pragma in VC6 that will activate or deactivate optimization. It can be used to wrap optimization-sensitive blocks of code. I do not remember what it is, though, and I do not have VC6 handy. I have used it, and it did alleviate an optimization-related bug. John -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Peter Dimov Sent: Wednesday, April 19, 2006 10:45 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] [weak_ptr] thread safe? Alain Cormier wrote:
So, can I conclude that it is a bad behavior in boost::weak_ptr?
No, it is a bug in VC6.
For now, I have simply changed add_ref_lock to :
long tmp2 = tmp + 1; if(InterlockedCompareExchange ( &use_count_, tmp2, tmp ) == tmp2 - 1 ) return true;
This way, VC6 doesn't optimise the return value of InterlockedCompareExchange and the disassembly looks ok.
I don't think that there is any guarantee that this modification will reliably produce correct code, even if it happens to work in the examples we try. But if we can't think of a better way to work around the issue, this may be our best bet. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users