Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com Subject: RE: Strange fork() behaviour under cygwin v1.3.1 Date: Tue, 22 May 2001 09:56:01 +1000 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Message-ID: X-MS-Has-Attach: content-class: urn:content-classes:message X-MimeOLE: Produced By Microsoft Exchange V6.0.4417.0 X-MS-TNEF-Correlator: Thread-Topic: Strange fork() behaviour under cygwin v1.3.1 Thread-Index: AcDiSqD7Tt5uhZtDQ8Oxl1lksgLuKQABEu8w From: "Robert Collins" To: "Andrew de Quincey" , Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id UAA14337 > -----Original Message----- > From: Andrew de Quincey [mailto:andrew AT orbital DOT co DOT uk] > Sent: Tuesday, May 22, 2001 9:01 AM > To: cygwin AT cygwin DOT com > Subject: Strange fork() behaviour under cygwin v1.3.1 > > > > Hi, I've been playing with the jabber server under win32... > and I've run > into a slight problem. The following program illustrates it: > > +++++++++++++++++++++++++++++++++++++++++++++++++ > #include Whats ? If it's the GNU portable threads library, and it's using a native thread library instead of 100% emulated threads, make sure its using pthreads, not win32 threads. (Explanation: Cygwin is ignorant of direct win32 thread calls you might make, but it knows about pthreads). > #include > > void *test(void *arg); > > int main(int argc, char* argv[]) { > int pid; > pth_init(); > > pth_join(pth_spawn(PTH_ATTR_DEFAULT, test, NULL), NULL); > } > > void *test(void *arg) { > int pid; > > pid = fork(); > if (pid < 0) { > printf("FORKFAILED\n"); > } else if (pid == 0) { > printf("FORKCHILD\n"); > } else { > printf("FORKPARENT\n"); > } > } ****** IMPORTANT ******* When writing or testing threading code, ___always___ check return values and error flags. I realise that that isn't the problem here: your thread function does run, but all the same! ************************ > +++++++++++++++++++++++++++++++++++++++++++++++++ > > This outputs the following when run: > 0 [main] a 1760 sync_with_child: child 1524(0x23C) died before > initialization with status code 0x1 > 2496 [main] a 1760 sync_with_child: *** child state > waiting for longjmp > FORKFAILED > > > Is this a known problem, not being able to fork() once you > are inside a > spawned thread? Or, is this a bug I have run across...? I strongly suspect the pth library is using native win32 threads, not pthreads. I'm using cygwin 1.3.2, but I don't recall any fork() fixes in the update. my test program output: $ ./ptfork.exe FORKPARENT FORKCHILD and the program: ==== $ cat ptfork.c #include #include #include #include void *test(void *arg); int main(int argc, char* argv[]) { int err; pthread_t thread; void * threadrv; if ((err = pthread_create(&thread, NULL, test, NULL))) { printf("Error on pthread_create %d:%s\n",err,strerror(err)); exit(1); } if ((err = pthread_join(thread, &threadrv))) { printf("Error on pthread_join %d:%s\n",err,strerror(err)); exit(1); } } void *test(void *arg) { int pid; pid = fork(); if (pid < 0) { printf("FORKFAILED\n"); } else if (pid == 0) { printf("FORKCHILD\n"); } else { printf("FORKPARENT\n"); } } Rob > BTW: I'm using cygwin dll 1.3.1, pth 1.4.0, and win2k SP1 > > > > -- > Want to unsubscribe from this list? > Check out: http://cygwin.com/ml/#unsubscribe-simple > > -- Want to unsubscribe from this list? Check out: http://cygwin.com/ml/#unsubscribe-simple