671 Subj : Re: Stack in thread-local virtual memory? To : comp.programming.threads From : Ulrich Eckhardt Date : Tue Aug 23 2005 08:14 am David Hopwood wrote: > Ulrich Eckhardt wrote: >> foo a_foo; >> thread t = create_thread( &thread_entry, &a_foo); >> join(t); > > Can 'join' fail? This is all pseudocode, the 'foo' was a handle to an event, the join() was in fact a WaitForSingleObject() on that event without a timeout. I tried to make sure that I check each and every call's returnvalue for failure, too. Using debugging output, I was able to see that the program did nothing unusual or unexpected, except for the already described access violation on the main thread's stack. >> Simple thing, fork off a worker thread and wait until it has finished - >> to be precise I only waited until it had initialised and passed an >> pointer to a win32 event handle, but for sure I did not return from >> main() so the reference to a_foo was valid all the time. > > This looks like the kind of code that could be mis-optimized by a > compiler that is not sufficiently aware of threading. In a > single-threaded program, depending on the code of 'join', it could > be correct to treat a_foo as dead after the create_thread call. No, I still used the a_foo (an event handle) afterwards in order to wait for the forked thread to signal it. > I gather that since you no longer have access to the machine where it > failed, you can't disassemble main() to see whether it looks correct? I'm contemplating rebuilding that environment - not knowing what was going on there is making me nuts. :( Uli . 0