strange behavior with threads...

Dave Korn dave.korn.cygwin@googlemail.com
Thu Jul 23 18:16:00 GMT 2009


jean-luc malet wrote:
> Hi!
> I've the following code :
> void _Window::Start(void* arg)
> {
>         ThreadArgs args;

  This allocates a ThreadArgs struct on the stack.

>         int err = pthread_create(&main_thread,NULL,_Start, (void*)&args);

  This passes a pointer to the ThreadArgs struct on the stack to the new thread.

>         if (err)
>         {
>                 throw new  Exception(err, "window thread creation error");
>         }
> }

  This then immediately exits and deallocates the stack frame, making the
&args pointer you passed to the main_thread invalid.

    cheers,
      DaveK


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list