Mailing-List: contact cygwin-developers-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-developers-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin-developers AT sources DOT redhat DOT com Date: Fri, 18 May 2001 22:45:35 -0400 From: Christopher Faylor To: cygwin-developers AT cygwin DOT com Subject: Re: pthread gotchas Message-ID: <20010518224535.A26035@redhat.com> Reply-To: cygwin-developers AT cygwin DOT com Mail-Followup-To: cygwin-developers AT cygwin DOT com References: <20010518221107 DOT A12195 AT redhat DOT com> <021a01c0e00b$e8d48dc0$0200a8c0 AT lifelesswks> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.11i In-Reply-To: <021a01c0e00b$e8d48dc0$0200a8c0@lifelesswks>; from robert.collins@itdomain.com.au on Sat, May 19, 2001 at 12:32:10PM +1000 On Sat, May 19, 2001 at 12:32:10PM +1000, Robert Collins wrote: >----- Original Message ----- >From: "Christopher Faylor" >Subject: pthread gotchas > >>Just to be clear up front, the gotchas I'm talking about are my >>gotchas. There were apparently some aspects of the way that pthreads >>work that I was not familiar with. > >Same here. :] > >>I am looking into finally getting signals working in a multi-threaded >>enviroment given Corinna's recent problems with cygrunsrv. So, I wrote >>a program which forked, started a separate thread, and then called >>waitpid(). I wanted to see how a SIGINT with a signal handler would >>work with pthreads. I ran the program on linux. ^^^^^^^^^^^^^^^^^^^^^^^^^^ > >**** MOST IMPORTANT **** >I think delivering signals to threads is broken. I cannot >see where you use getthread2signal in signal.cc. That would >break waitpid the way you see it broken. >**** **** The whole point of my efforts is to get signals working with threads on cygwin. I know that they are broken. The above is just the tip of the iceberg. The signal delivery mechanism doesn't even attempt to take multiple threads into account. I've tried to carefully make stuff thread safe but I still have a ways ago to get the signal mechanism to be able to send signals to any thread other than the main one. This email was talking about linux. I ran the program on linux first so that I could get a feel for how it was supposed to work and was surprised to find that linux broke my perceptions. I have included my test program below. The waitpid, which is invoked in the secondary thread fails unless I move the fork into the same thread. I'd still be interested in hearing if there is a good pthreads reference book which talks about this kind of stuff. cgf #include #include #include static int pid = 0; static void * tf (void *v) { int status; printf ("in tf, waiting for %d\n", pid); printf ("%d = waitpid\n", status = waitpid (pid, NULL, 0)); if (status) perror ("waitpid"); puts ("returning"); return NULL; } int main (int argc, char **argv) { pthread_t tid; pthread_attr_t att = {0}; void *thread_return; setbuf (stdout, NULL); if ((pid = fork ()) == 0) { puts ("in subproc, sleeping"); sleep (10); puts ("in subproc, exiting"); exit (0); } printf ("in parent, starting thread, pid %d", pid); printf ("%d = pthread_create\n", pthread_create (&tid, NULL, tf, NULL)); printf ("%d = pthread_join\n", pthread_join (tid, &thread_return)); puts ("exiting"); }