delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/02/12/15:18:58

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Date: Fri, 12 Feb 2010 15:08:51 -0500
From: Christopher Faylor <cgf-use-the-mailinglist-please AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: pthread problem
Message-ID: <20100212200851.GB8731@ednor.casa.cgf.cx>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <ce3537cc1002051043l57cdeef2j268592189cc9c24 AT mail DOT gmail DOT com> <20100205190006 DOT GA9938 AT ednor DOT casa DOT cgf DOT cx>
MIME-Version: 1.0
In-Reply-To: <20100205190006.GA9938@ednor.casa.cgf.cx>
User-Agent: Mutt/1.5.20 (2009-06-14)
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
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 Fri, Feb 05, 2010 at 02:00:07PM -0500, Christopher Faylor wrote:
>On Sat, Feb 06, 2010 at 12:13:59AM +0530, Gaurav Sachdeva wrote:
>>Hi,
>>
>>I have written following code -
>>
>>#include<stdio.h>
>>
>>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.

This should be fixed in today's snapshot.  Thanks for the test case.

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019