delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/04/13/19:56:42

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Message-ID: <04e501c0c475$3d059e50$0200a8c0@lifelesswks>
From: "Robert Collins" <robert DOT collins AT itdomain DOT com DOT au>
To: "Billinghurst, David \(CRTS\)" <David DOT Billinghurst AT riotinto DOT com>,
<cygwin AT cygwin DOT com>, <cygwin-patches AT cygwin DOT com>
References: <8D00C32549556B4E977F81DBC24E985DC80C AT crtsmail1 DOT technol_exch DOT corp DOT riotinto DOT org>
Subject: [PATCH] Re: pthreads update for the adventurous
Date: Sat, 14 Apr 2001 09:55:35 +1000
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
X-OriginalArrivalTime: 13 Apr 2001 23:48:49.0806 (UTC) FILETIME=[49B282E0:01C0C474]

------=_NextPart_000_04E2_01C0C4C9.0D65F470
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Thanks for the report David. That bugs been in cygwin's pthread support
forever - but it's gone now. (Cross fingers)

If you apply the attached patch to your CVS working directory and make a
new cygwin1.dll the test should pass.

Otherwise, you can wait for the next snapshot.

Chris: I hope the changelog and patch are ok..

==
Saturday Apr 14 2001  Robert Collins <rbtcollins AT hotmail DOT com>
 * thread.h (MTinterface): Add threadcount.
 * thread.cc (MTinterface::Init): Set threadcount to 1.
 (__pthread_create): Increment threadcount.
 (__pthread_exit): Decrement threadcount and call exit() from the last
thread.
==

Rob

----- Original Message -----
From: "Billinghurst, David (CRTS)" <David DOT Billinghurst AT riotinto DOT com>
To: <cygwin AT cygwin DOT com>
Sent: Friday, April 13, 2001 10:55 PM
Subject: RE: pthreads update for the adventurous


> OK.  I'll bite.
>
> I have built cygwin1.dll from cvs, then proceeded to build and test
gcc-3.0
> with --enable-threads=posix.  This seems to work OK.
>
> I then tried example 1 from
>
http://www.llnl.gov/computing/tutorials/workshops/workshop/pthreads/MAIN
.htm
> l (below) using standard cygwin gcc-2.95.3-2 and the gcc-3.0 I built.
There
> appears to be a problem with pthread_exit() as the program never
exits.  I
> tried to debug this, but soon got lost.
>
>
>
>
/***********************************************************************
****
> ***
> * FILE: hello.c
> * DESCRIPTION:
> *   A "hello world" Pthreads program.  Demonstrates thread creation
and
> *   termination.
> *
> * SOURCE:
> * LAST REVISED: 9/20/98 Blaise Barney
>
************************************************************************
****
> **/
>
> #include <pthread.h>
> #include <stdio.h>
> #define NUM_THREADS 5
>
> void *PrintHello(void *threadid)
> {
>    printf("\n%d: Hello World!\n", threadid);
>    pthread_exit(NULL);
> }
>
> int main()
> {
>    pthread_t threads[NUM_THREADS];
>    int rc, t;
>    for(t=0;t<NUM_THREADS;t++){
>       printf("Creating thread %d\n", t);
>       rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
>       if (rc){
>          printf("ERROR; return code from pthread_create() is %d\n",
rc);
>          exit(-1);
>       }
>    }
>    pthread_exit(NULL);
> }
>
>
> --
> Want to unsubscribe from this list?
> Check out: http://cygwin.com/ml/#unsubscribe-simple
>
>

------=_NextPart_000_04E2_01C0C4C9.0D65F470
Content-Type: application/octet-stream;
	name="pthread_exit.ChangeLog"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="pthread_exit.ChangeLog"

Saturday Apr 14 2001  Robert Collins <rbtcollins AT hotmail DOT com>=0A=
	* thread.h (MTinterface): Add threadcount.=0A=
	* thread.cc (MTinterface::Init): Set threadcount to 1.=0A=
	(__pthread_create): Increment threadcount.=0A=
	(__pthread_exit): Decrement threadcount and call exit() from the last =
thread.=0A=

------=_NextPart_000_04E2_01C0C4C9.0D65F470
Content-Type: application/octet-stream;
	name="pthread_exit.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="pthread_exit.patch"

Index: thread.h=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /cvs/src/src/winsup/cygwin/thread.h,v=0A=
retrieving revision 1.16=0A=
diff -u -p -r1.16 thread.h=0A=
--- thread.h	2001/04/13 15:28:20	1.16=0A=
+++ thread.h	2001/04/13 23:50:14=0A=
@@ -333,6 +333,7 @@ public:=0A=
   /* we may get 0 for the Tls index.. grrr */=0A=
   int indexallocated;=0A=
   int concurrency;=0A=
+  long int threadcount;=0A=
 =0A=
   // Used for main thread data, and sigproc thread=0A=
   struct __reent_t reents;=0A=
@@ -346,7 +347,7 @@ public:=0A=
 =0A=
   void Init (int);=0A=
 =0A=
-    MTinterface ():reent_index (0), indexallocated (0) =0A=
+    MTinterface ():reent_index (0), indexallocated (0), threadcount (1)=0A=
   {=0A=
     pthread_prepare =3D NULL;=0A=
     pthread_child   =3D NULL;=0A=
Index: thread.cc=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /cvs/src/src/winsup/cygwin/thread.cc,v=0A=
retrieving revision 1.23=0A=
diff -u -p -r1.23 thread.cc=0A=
--- thread.cc	2001/04/13 15:28:20	1.23=0A=
+++ thread.cc	2001/04/13 23:50:16=0A=
@@ -291,6 +291,7 @@ MTinterface::Init (int forked)=0A=
     }=0A=
 =0A=
   concurrency =3D 0;=0A=
+  threadcount =3D 1; /* 1 current thread when Init occurs.*/=0A=
 =0A=
   if (forked)=0A=
     return;=0A=
@@ -664,6 +665,7 @@ __pthread_create (pthread_t * thread, co=0A=
       *thread =3D NULL;=0A=
       return EAGAIN;=0A=
     }=0A=
+  InterlockedIncrement(&MT_INTERFACE->threadcount);=0A=
 =0A=
   return 0;=0A=
 }=0A=
@@ -1214,10 +1216,12 @@ __pthread_exit (void *value_ptr)=0A=
   class pthread *thread =3D __pthread_self ();=0A=
 =0A=
   MT_INTERFACE->destructors.IterateNull ();=0A=
-// FIXME: run the destructors of thread_key items here=0A=
 =0A=
   thread->return_ptr =3D value_ptr;=0A=
-  ExitThread (0);=0A=
+  if (InterlockedDecrement(&MT_INTERFACE->threadcount) =3D=3D 0)=0A=
+    exit (0);=0A=
+  else=0A=
+    ExitThread (0);=0A=
 }=0A=
 =0A=
 int=0A=


------=_NextPart_000_04E2_01C0C4C9.0D65F470
Content-Type: text/plain; charset=us-ascii

--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple
------=_NextPart_000_04E2_01C0C4C9.0D65F470--

- Raw text -


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