
7 Mar
2011
7 Mar
'11
2:37 a.m.
Chad Nelson wrote:
The only concrete complaint that people could give me about CoW was that code using it couldn't be made thread-safe, which is true. So I made a way to instruct the library to force all integer objects to have unique storage before they're returned to user code, and made it the default to prevent unpleasant client-code surprises.
I don't think that this is enough to prevent surprises. If someone does thread t( f, x ); where x is an integer, the thread would receive a shared copy of x. The user would need to explicitly call the copy constructor with a second argument of true to avoid that. Just use detail::atomic_count until C++0x atomics arrive in numbers. :-)