Boost logo

Boost :

From: williamkempf_at_[hidden]
Date: 2001-08-22 07:58:07

--- In boost_at_y..., "Alexander Terekhov" <terekhov_at_d...> wrote:
> > Hmm... I was not aware that POSIX operated this way. Seems to me
> > that this means the pthreads-win32 isn't compliant (unless they
> > found some way to work around this).
> > The main thread on Win32 is synonymous with the process...
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> "Remarks
> ExitThread is the preferred method of exiting a thread.
> When this function is called (either explicitly or by
> returning from a thread procedure), the current thread's
> stack is deallocated and the thread terminates. The
> entry-point function of all attached dynamic-link
> libraries (DLLs) is invoked with a value indicating
> that the thread is detaching from the DLL.
> If the thread is the last thread in the process when this
> function is called, the thread's process is also terminated."

This does not mention the main thread of control explicitly. And in
fact the documentation is wrong, though it turns out you are
partially correct in that _endthread et. al. on the main thread does
not terminate the process. I say partially correct and claim the
documentation is wrong from personal experience and some
experimentation to see what the truth is. The simple program that
follows will help illustrate:

#include <process.h>
#include <windows.h>

unsigned __stdcall thread(void*)
        for(;;) { }
        return 0;

int main()
        unsigned id;
        unsigned long thrd = _beginthreadex(0, 0, &thread, 0, 0, &id);
        return 0;

When run this program never ends, illustrating your point about
_endthreadex et. al. However, comment out the _endthreadex line and
the program terminates immediately even though the documentation you
quote above indicates that returning from a thread's entry routine
automatically calls _endthreadex. In this regard the main thread is
unique and the documentation simply doesn't cover the semantics.
Another example where things are different is with a call to
TerminateThread, which I believe also terminates the entire process.

It still seems to me that POSIX and Win32 differ in how this works.

Bill Kempf

Boost list run by bdawes at, gregod at, cpdaniel at, john at