
18 Dec
2007
18 Dec
'07
11:12 a.m.
Zeljko Vrba [zvrba@ifi.uio.no] wrote:
He might just allocate the shared_ptr on the heap (the dynamic memory allocation will be anyway cheaper than thread creation):
void *thread(void *ptr) { shared_ptr<X> *_p = static_cast<shared_ptr<X>*>(ptr); shared_ptr<X> p = *_p; delete _p; ... }
void creator() { ... pthread_create(&thrid, 0, thread, new shared_ptr<X>(orig_ptr)); ... }
No need for any additional synchronization.
Good point. And certainly much simpler than my solution.