This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: child thread termination causes main thread error termination


Unfortunately the code does not function that way on my machine.  The code 
contrary to Brian's snipe is mine and was used in a demo of pthreads for my
class.  It works fine under multiple version of Unix and Linux but does not
work on my Windows XP Pro machine under cygwin.  What I get is the following
output.


/lab4/ $ lab4_1
waiting do_one_thing
waiting do_another_thing
Ready to start threads ..... 
&Starting ... do_one_thing
Starting ... do_another_thing
+-+-+-+-+-+-+-+-++-++++-++--+-+-+-+-----+--+++-++++++--+-+-+-+-++-+-++-+-+-+-+-+-+-++++-+-+-+-+-+-+-+-+--+--+++++-+-+-+++-+-+-+-++-+-+++-+-+-+-++++++-+-++-+-+-+-+-+-+-+-++-++@(!(/lab4/ $ 

If I uncomment the sleeps in the two threads and comment out the pthread_join
calls I get the following out as I would expect.

/lab4/ $ lab4_1
waiting do_one_thing
waiting do_another_thing
Ready to start threads ..... 
&Starting ... do_one_thing
Starting ... do_another_thing
+-+-+-+-+-+-+-+-+-+-+-+++-+++-+-++-++-++-+-+-++++--++---+--+-++---++-+-+-++-+-+-+++++-++++--+-+-++-+-++-+--+-+-+-+-+-+-+++++-+-++++-++--+-+-+-++-+-++-+++-+----++-+--+-+-++-++@(!(#&--------------------------@)#^
All threads complete

wrap up: doing another 100, another 100, total 200
!)
/lab4/ $ 


As noted the code as attached does not compile but the missing header file
only contained the  following code:

/*

    Common Local Header File: local_mutex.h

*/

#ifndef LOCAL_MUTEX_H
#define LOCAL_MUTEX_H
#define _REENTRANT
#include    <pthread.h>
#include    <stdio.h>
#include    <stdlib.h>
#include    <unistd.h>
#include    <sys/types.h>
#include    <sys/time.h>
#include    <sys/wait.h>

#endif


So adding pthread.h was all that was needed.  Since others have added the output
as I would expect I am assuming that the problem is in my cygwin environment. To
confirm that nothing I had added was causing this issue I removed my local_mutex.h
include and just used pthread.h.  The following is the output:

/labs/lab4/ $ make lab4_1
gcc -c -pg -g -Dcygwin -I ./inc/ lab4_1.c
gcc -pg -o lab4_1 lab4_1.o 
/labs/lab4/ $ lab4_1
waiting do_one_thing
waiting do_another_thing
Ready to start threads ..... 
&Starting ... do_one_thing
Starting ... do_another_thing
+-+-+-+--+-+-+-+-+-+--+-+-------+++++--+-+-+-+-+-+-----+---+--++-+-+-+-+-+-+-+-+--------+-+-+-+-+-+-+-++++-+-+-+--+-+-+-+-----+++++++--++++-++-----+---+-+-+-++--+-+-++-+-----+--+-@)!)+/labs/lab4/

Running this application in the Unix (AIX, Solaris, HP/UX, SCO, DigitalUnix) and
Linux (Red Hat 7.3, Slackware, Debian, Fedora Core 2) produces the correct output
so I am trying to find out what in my environment produces the incorrect
behavior.  I had made the rash assumtion that others testing this code in a basic
cygwin environment would encounter the same errors as I was seeing but the output
So far shows that is not the case.



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]