Boost logo

Boost :

From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2001-07-31 12:34:19


> It's very close to being ready. Beman and I are currently working
> hard on the documentation and cleaning up some issues revealed by
> this work.

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
}

thread::~thread()
{
    int res = 0;
#if defined(BOOST_HAS_WINTHREADS)
    res = CloseHandle(reinterpret_cast<HANDLE>(m_thread));
    assert(res);
#elif defined(BOOST_HAS_PTHREADS)
    {
        mutex::lock lock(m_mutex);
        if (m_state_manager)
            m_state_manager->remove(this);
    }

    res = pthread_detach(m_thread);
    assert(res == 0);
#endif
}

do you really want pthread_detach after each
pthread_self() !? this is hardly what is needed
here unless i am missing something big. also,
your DuplicateHandle/CloseHandle is really an
overkill.. keeping just ONE handle and TLS/TSD
key association is much more attractive/
efficient, IMHO.

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

regards,
alexander.


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