Re: [sigc] Re: [gtkmm] libsigcx and gtkmm 2.4



Am Mo, den 14.06.2004 um 10:07 Uhr +0200 schrieb Martin Schulze:

> Hm... after reading:
> 
>   http://gcc.gnu.org/onlinedocs/libstdc++/faq/#5_6
> 
> I still cannot answer the question whether string (in the example from  
> above) _is_ thread-safe?!

Well, std::string in libstdc++ uses atomic increment and decrement for
the reference count.  However, the problem is that you cannot rely on
this since the standard doesn't say anything about it AFAIK.  Also, I'm
not sure if an atomic reference count is actually sufficient to always
guarantee thread-safety... suppose you have:

std::string a ("foo");  // in thread 1
std::string b (a);      // in thread 2
b[2] = 'b';             // mutate to force copy (in thread 2)

Now, atomic reference count or not, you have the situation that
thread 2 reads memory written by thread 1 without any mutex locking.
Well, unless atomic inc/dec also have the effect of a memory barrier,
which would make them rather heavy...

--Daniel





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]