Boost logo

Boost :

From: John Torjo (john.lists_at_[hidden])
Date: 2004-09-22 08:56:19


Hi Peter,

I think there is a bug in your Interlocked* implementation of shared_ptr
  (http://www.pdimov.com/cpp/shared_count_x86_exp2.hpp).

In atomic_read you have:
inline long atomic_read(long volatile const & value)
{
     return value;
}

I don't believe this is thread-safe.
In order to make sure you're receiving the latest value, I assume you
could do something like:

inline long atomic_read(long volatile & value)
{
     const int IMPOSSIBLE_VALUE = -100;
     return InterlockedCompareExchange(&value, IMPOSSIBLE_VALUE,
IMPOSSIBLE_VALUE);
}

Am I missing something?

Best,
John

-- 
John Torjo
-- john_at_[hidden]
Contributing editor, C/C++ Users Journal
-- "Win32 GUI Generics" -- generics & GUI do mix, after all
-- http://www.torjo.com/win32gui/
-- v1.4 - save_dlg - true binding of your data to UI controls!
    + easily add validation rules (win32gui/examples/smart_dlg)

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk