Subject: Re: pthread_create -- no callback?
From: Evan Pollan <[email-masked]>
To: "Lassi A. Tuura" <[email-masked]>
Cc: [email-masked]
Date: Wed, 14 Nov 2001 06:18:05 -0800 (PST)

Lassi--

The sample I included did check the return value of pthread_join.  I now have
it also checking the return value of pthread_create.  So, pthread_create
returns sucessfully, the callback never gets invoked, and pthread_join
indicates that the thread exited with an error.

Gareth Pearce seems to recall reading that pthread_join isn't implemented in
1.3.5...  Is this correct?

Anyhow, again, here's the (updated) sample code and the resulting output:

#include "pthread.h"
#include <iostream>

extern "C" void* callbackFunction (void*);

void* callbackFunction (void* arg) {
    cout << "--> callbackFunction(" << (arg==NULL ? "NULL" : arg) << ")\n";
    return NULL;
}

int main (int numArgs, char** args) {

    pthread_t thread;

    pthread_attr_t pta;
    pthread_attr_init(&pta);

    cout << "--> pthread_create()\n";
    int retVal = pthread_create(&thread, &pta, callbackFunction, NULL);
    cout << "<-- pthread_create():" << retVal << "\n";
    
    void* threadExitStatus;
    cout << "--> pthread_join()\n";
    pthread_join(&thread, &threadExitStatus);
    cout << "<-- pthread_join():" << (int)threadExitStatus << "\n";
}

*******************************
make.exe: Entering directory `/cygdrive/c/home/src/c++/PThreadTest'
rm -f  PThreadTest.o PThreadTest
g++ -W -Wall -Wno-non-virtual-dtor -Wwrite-strings -Wpointer-arith
-Wnested-externs -Woverloaded-virtual -Wbad-function-cast -ansi -pedantic -c
PThreadTest.cpp -o PThreadTest.o
PThreadTest.cpp: In function `int main(int, char **)':
PThreadTest.cpp:11: warning: unused parameter `int numArgs'
PThreadTest.cpp:11: warning: unused parameter `char ** args'
g++ -W -Wall -Wno-non-virtual-dtor -Wwrite-strings -Wpointer-arith
-Wnested-externs -Woverloaded-virtual -Wbad-function-cast -ansi -pedantic
PThreadTest.o -o PThreadTest
make.exe: Leaving directory `/cygdrive/c/home/src/c++/PThreadTest'

Output:

--> pthread_create()
<-- pthread_create():0
--> pthread_join()
<-- pthread_join():1627734452

Ideas!?!?!  Again, this is Cygwin 1.3.5 (and all other packages as of 2 days
ago) on a Win2000 Professional box.

thanks,
Evan

--- "Lassi A. Tuura" <[email-masked]> wrote:
> > Yeah, arg problem noted.  Oversight on my part, thanks.  However, the
> thread
> > callback still appears to be a problem.  Here's a more simplified example:
> 
> Compile with warnings; on linux I use: g++ -W -Wall
> -Wno-non-virtual-dtor -Wwrite-strings -Wpointer-arith -Wnested-externs
> -Woverloaded-virtual -Wbad-function-cast -ansi -pedantic -pthread.
> 
> Check the pthread return values for errors.
> 
> Doing either of these will show you exactly where your problem is.  Make
> both practises a habit.
> 
> HTH,
> //lat
> -- 
> This planet has -- or rather had -- a problem, which was this: most
> of the people living on it were unhappy for pretty much of the time.
> Many solutions were suggested for this problem, but most of these
> were largely concerned with the movements of small green pieces of
> paper, which is odd because on the whole it wasn't the small green
> pieces of paper that were unhappy.  --Douglas Adams

__________________________________________________
Do You Yahoo!?
Find the one for you at Yahoo! Personals
http://personals.yahoo.com

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/