Boost logo

Boost :

From: scleary_at_[hidden]
Date: 2001-07-31 12:46:14


> have a look at:
>
> thread::thread()
> {
> #if defined(BOOST_HAS_WINTHREADS)
> HANDLE cur = GetCurrentThread();
> HANDLE real;
> DuplicateHandle(GetCurrentProcess(), cur,
> GetCurrentProcess(), &real,
> 0, FALSE, DUPLICATE_SAME_ACCESS);
> m_thread = reinterpret_cast<unsigned long>(real);
> m_id = GetCurrentThreadId();
> #elif defined(BOOST_HAS_PTHREADS)
> m_thread = pthread_self();
> m_state_manager = get_list();
> m_state_manager->add(this);
> #endif
> }

<snip>

> your DuplicateHandle/CloseHandle is really an
> overkill.. keeping just ONE handle and TLS/TSD
> key association is much more attractive/
> efficient, IMHO.

No, DuplicateHandle/CloseHandle is required. GetCurrentThread() returns a
psuedohandle, not a real handle.

> why not "static thread& thread::current()" ?

Think of other threads that need to see that thread's handle.

        -Steve


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk