Boost logo

Boost Users :

From: Yuval Ronen (ronen_yuval_at_[hidden])
Date: 2004-12-08 04:44:18


Hi.
I believe that there is a bug in thread::thread() under Windows.
The code uses GetCurrentThread() WinAPI function, but this is not enough. If
you'll try to create such a thread object, and pass its reference to another
thread which will join it - something like

    struct SomeThread
    {
        thread *m_thread;
        SomeThread(thread *a_thread) : m_thread(a_thread) { }
        void operator()()
        {
            do_some_work()
            m_thread->join();
            delete m_thread;
        }
    };

    {
        ...somewhere in the code...
        SomeThread st(new thread());
        thread other_thread(st);
    }

then it won't work.

The following is a quote from MSDN about GetCurrentThread():
"The return value is a pseudo handle for the current thread... A pseudo
handle is a special constant that is interpreted as the current thread
handle... The function cannot be used by one thread to create a handle that
can be used by other threads to refer to the first thread. The handle is
always interpreted as referring to the thread that is using it. A thread can
create a "real" handle to itself that can be used by other threads, or
inherited by other processes, by specifying the pseudo handle as the source
handle in a call to the DuplicateHandle function."

The conclusion is that a call to DuplicateHandle() is needed after
GetCurrentThread().

Thanks,
Yuval


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net