X-Recipient: archive-cygwin AT delorie DOT com X-Spam-Check-By: sourceware.org Date: Fri, 5 Feb 2010 14:00:07 -0500 From: Christopher Faylor To: cygwin AT cygwin DOT com Subject: Re: pthread problem Message-ID: <20100205190006.GA9938@ednor.casa.cgf.cx> Reply-To: cygwin AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: 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 On Sat, Feb 06, 2010 at 12:13:59AM +0530, Gaurav Sachdeva wrote: >Hi, > >I have written following code - > >#include > >void *thread_func(void *data) >{ > printf("In thread\n"); > pthread_exit(NULL); >} > >int main() >{ > pthread_t mythread; > int rc; > > rc = pthread_create(&mythread, NULL, thread_func, NULL); > if (rc){ > printf("ERROR; return code from pthread_create() is %d\n", rc); > exit(-1); > } > > printf("In main..\n"); > > pthread_exit(NULL); >} > >It must print both "In main" and "In thread". >But sometimes it prints one of these two and sometimes both. >I tried in actual UNIX OS. It always prints both. > >I also tried in c++ in cygwin, problem exists there also. > >Is anyone aware of this problem and its solutions? Looks like a bug in Cygwin. From my reading of the pthread_exit man page, it looks like it should wait for all available threads to exit before the process exits. Unfortunately that doesn't happen. You can probably fix that by adding a pthread_join() before the pthread_exit(). In the meantime, I'll look into fixing this. cgf -- 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