AMDG Jason Cipriani wrote:
Finally, you could use enable_shared_from this, to allow a shared_ptr to be recovered from a raw pointer.
Hmm, is there a way to do something like this (the following code is broken):
class Item : public enable_shared_from_this<Item> { ... };
DWORD WINAPI threadproc (LPVOID vitem) { shared_ptr<Item> s = ((Item *)vitem)->shared_from_this(); ... }
void start5threads () { shared_ptr<Item> p(new Item); CreateThread(..., &threadproc, (LPVOID)p.get(), ...); CreateThread(..., &threadproc, (LPVOID)p.get(), ...); CreateThread(..., &threadproc, (LPVOID)p.get(), ...); CreateThread(..., &threadproc, (LPVOID)p.get(), ...); CreateThread(..., &threadproc, (LPVOID)p.get(), ...); }
... that doesn't require any special synchronization to avoid 'p' in start5threads going out of scope (and deleting the Item) before 's' is initialized in any of the threads?
Oh, right. Never mind that idea. In Christ, Steven Watanabe