X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_93,SPF_PASS X-Spam-Check-By: sourceware.org Message-ID: <4A687264.4080206@gmail.com> Date: Thu, 23 Jul 2009 15:23:32 +0100 From: Dave Korn User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: strange behavior with threads... References: <1de9d39c0907230650t3ae02e2agc540e9ef8fe4ca34 AT mail DOT gmail DOT com> In-Reply-To: <1de9d39c0907230650t3ae02e2agc540e9ef8fe4ca34@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com 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