
Hi,
As I understand from documentation, once thread_specific_ptr is created,
first call to get() should return NULL in all threads. Actually sometimes it
doesn't happen. Consider the following scenario:
1) thread T1 initializes some global tss object (by doing "new" on global
thread_specific_ptr<>*)
2) thread T2 tries to read the value with get(), and gets null. It sets a
correct value (unsigned int 42)
3) thread T1 deletes tss object, and allocates a new one instead.
4) thread T2 tries to read the value from the new object
So I expected that in (4) thread T2 will get NULL again. Actually, when new
object created in (3) is created in same memory location, T2 gets the
original value in (4), and not NULL. When new pointer allocated in (3) is
different, T2 gets NULL as expected (verified using "placement new" to
control location of the tss object).
Is it a bug or inpropriate use pattern?
The code that demonstrates the issue is listed below (please ignore
synchronization issues) - note the line with a comment: when I do "new
(buf2) ..." instead, it works as expected.
Thanks,
Michael
======================================
#include