This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: strange behavior with threads...


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]