public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* pthread_create -- no callback?
@ 2001-11-01 21:42 Evan Pollan
  2001-11-02  0:09 ` Lassi A. Tuura
  2001-11-11  8:26 ` Evan Pollan
  0 siblings, 2 replies; 17+ messages in thread
From: Evan Pollan @ 2001-11-01 21:42 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 2574 bytes --]

Thanks for the help inre: getting a linkable pthreads library.  I have
1.3.5 installed and can link (using pthreads, pthread_cond, and pthread_mutex
calls).  However, I can't get pthread_create to call back into my startup
function...

I'm writing a QueueProcessor (producer-consumer pattern) that accepts
implementations of a Task interface.  The QueueProcessor is essentially
a thread pulling Tasks off an STL list + the cond/mutex code to handle the
wait/notify inter-thread communication.

Attached is the source for the QueueProcessor/Task and a test driver.  I've
also attached the output to illustrate the behavior.  Is there something I'm
doing wrong in the pthread_create call?  Notice that none of the messages in
the static driveQueue() call appear, nor anything from
QueueProcessor::processTasks().  The cond/mutex code
QueueProcessor::appendTask() and ::processTasks() is purely conjecture, as I
have no experience w/ POSIX thread wait/notify patterns (too used to the more
OO Java approach).

Ideas?  Any good online pthreads references/faq's that you'd recommend?


regards,
Evan


***
Here's the output:

------------------
QueueProcessor sucessfully constructed.
  --> pthread_create()
  <-- pthread_create()
QueueProcessor started successfully.
  --> joining against the queue thread...
  <-- join() returned...  This shouldn't happen!!!!
Appended Task[TestTask]
Appended Task[TestTask]
Appended Task[TestTask]
Appended Task[TestTask]
Appended Task[TestTask]
Appended Task[TestTask]
Appended Task[TestTask]
Appended Task[TestTask]
Appended Task[TestTask]
Appended Task[TestTask]
QueueProcessor shut down successfully.





--- Robert Collins <robert.collins@itdomain.com.au> wrote:
> From: "Robert Collins" <robert.collins@itdomain.com.au>
> To: "Evan Pollan" <evan_pollan@yahoo.com>,
> 	"Gerrit P. Haase" <cygwin@cygwin.com>
> Subject: Re: Cygwin && C++ POSIX threads support?
> Date: Sun, 11 Nov 2001 15:15:22 +1100
> 
> ----- Original Message -----
> From: "Evan Pollan" <evan_pollan@yahoo.com>
> To: "Gerrit P. Haase" <cygwin@cygwin.com>
> Sent: Sunday, November 11, 2001 3:12 PM
> Subject: Re: Cygwin && C++ POSIX threads support?
> 
> 
> > Great -- I'll pick up the kit tommorow over a more suitable
> > connection.  What's the preferred threading library?  POSIX?  Or
> > something a little more tuned to the Win32 env?
> >
> 
> Just link with no explicit library - the pthreads functions are in libc.
> 
> Rob
> 


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

[-- Attachment #2: QueueProcessor.h --]
[-- Type: text/plain, Size: 1274 bytes --]

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

#define ProcessingException 37

//-----------------------------------------------------------------------
// C-style call to drive the QueueProcessor
//-----------------------------------------------------------------------
extern "C" void* driveQueue (void*);

//-----------------------------------------------------------------------
// Task
//-----------------------------------------------------------------------

class Task {
 public:
    Task () {};

    virtual void execute () throw (int) = 0;

    virtual char* getDescription () {
        return "BaseTask";
    };
    
    friend ostream& operator<< (ostream& stream, Task* t) {
        stream << "Task[" << t->getDescription() << "]";
        return stream;
    };
};

//-----------------------------------------------------------------------
// QueueProcessor
//-----------------------------------------------------------------------

class QueueProcessor {
 private:
    bool _stopped;
    pthread_cond_t _condition;
    pthread_mutex_t _mutex;
    pthread_t _thread;
    list<Task*>* _queue;
    
 public:
    QueueProcessor ();
    ~QueueProcessor ();

    void appendTask (Task*);
    void start ();
    void stop ();
    void processTasks ();
};


[-- Attachment #3: QueueProcessor.cpp --]
[-- Type: text/plain, Size: 3053 bytes --]

#include "QueueProcessor.h"


//-----------------------------------------------------------------------
// C-style call to drive the QueueProcessor
//-----------------------------------------------------------------------

void* execute(void* args) {
    cout << "> Call into driveQueue()\n";
    QueueProcessor* p = (QueueProcessor*)args;
    p->processTasks();
    cout << "< QueueProcessor::processTasks() returned.\n";
    return NULL;
}

//-----------------------------------------------------------------------
// QueueProcessor
//-----------------------------------------------------------------------

QueueProcessor::QueueProcessor () {
    pthread_cond_init(&_condition, NULL);
    pthread_mutex_init(&_mutex, NULL);
    _stopped = false;
    _queue = new list<Task*>();
    cout << "QueueProcessor sucessfully constructed.\n";
}

QueueProcessor::~QueueProcessor () {
    pthread_cond_destroy(&_condition);
    pthread_mutex_destroy(&_mutex);
    delete _queue;
    cout << "QueueProcessor sucessfully destroyed.\n";
}

void QueueProcessor::appendTask (Task* t) {
    if (!_stopped) {

        pthread_mutex_lock(&_mutex);
        _queue->push_back(t);
        pthread_cond_signal(&_condition);
        pthread_mutex_unlock(&_mutex);

        cout << "Appended "<< t << "\n";
    } else {
        cout << "WARNING:  " << t << " added after the QueueProcessor was ";
        cout << "stopped.\n";
    }
}

void QueueProcessor::start () {
    cout << "  --> pthread_create()\n";
    int status = pthread_create(&_thread, NULL, execute, NULL);
    cout << "  <-- pthread_create()\n";

    if (status != 0) {
        cout << "ERROR: Thread creation failed (status=" << status << ").\n";
    } else {
        cout << "QueueProcessor started successfully.\n";
    }

    void* threadExitStatus;
    cout << "  --> joining against the queue thread...\n";
    pthread_join(&_thread, &threadExitStatus);
    cout << "  <-- join() returned...  This shouldn't happen!!!!\n";
}

void QueueProcessor::stop () {
    pthread_mutex_lock(&_mutex);
    _stopped = true;
    pthread_cond_signal(&_condition);
    pthread_mutex_unlock(&_mutex);
    
    void* threadExitStatus;
    pthread_join(&_thread, &threadExitStatus);
    cout << "QueueProcessor shut down successfully.\n";
}

void QueueProcessor::processTasks () {
    cout << "--> processTasks()\n";

    Task* t;
    while (!_stopped) {

        cout << "----> !_stopped\n";
        pthread_mutex_lock(&_mutex);
        while (_queue->size() == 0 && !_stopped) {
            pthread_cond_wait(&_condition, &_mutex);
        }
        pthread_mutex_unlock(&_mutex);

        if (_queue->size()>0 && !_stopped) {
            t=_queue->front();
            _queue->pop_front();
            try {
                t->execute();
            } catch (int i) {
                if (i == ProcessingException) {
                    cout << "Couldn't process "<< t << "\n";
                } else {
                    throw i;
                }
            }
        }
    }
    cout << "<-- processTasks()\n";
}


[-- Attachment #4: Driver.cpp --]
[-- Type: text/plain, Size: 689 bytes --]

#include "QueueProcessor.h"

class TestTask: public Task {
  private:
    int _size;

  public:
    TestTask (int i) {
        _size = i;
    }

    char* getDescription () {
        return "TestTask";
    }

    void execute () {
        cout << "Executing TestTask(" << _size << ")\n";
    }
};

int main (int, char*[]) {

    // Create and startup the QueueProcessor
    QueueProcessor* p = new QueueProcessor();

    p->start();

    // Add the tasks, allowing them to be processed asynchronously by the
    // QueueProcessor
    Task* t;
    for (int i=0; i<10; i++) {
        t = new TestTask(i);
        p->appendTask(t);
    }

    // Shutdown the QueueProcessor
    p->stop();
}


[-- Attachment #5: Type: text/plain, Size: 214 bytes --]

--
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/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: pthread_create -- no callback?
  2001-11-01 21:42 pthread_create -- no callback? Evan Pollan
@ 2001-11-02  0:09 ` Lassi A. Tuura
  2001-11-02  4:47   ` Evan Pollan
  2001-11-11  8:26   ` Lassi A. Tuura
  2001-11-11  8:26 ` Evan Pollan
  1 sibling, 2 replies; 17+ messages in thread
From: Lassi A. Tuura @ 2001-11-02  0:09 UTC (permalink / raw)
  To: Evan Pollan; +Cc: cygwin

> Is there something I'm doing wrong in the pthread_create call?

Yes, from a very superficial reading at least.

> void* execute(void* args) {

Here, you'll want non-zero `args'...

>     int status = pthread_create(&_thread, NULL, execute, NULL);

... and here you are passing null (the last argument).  Since
QueueProcessor::processTasks is not virtual, you are probably calling it
with null 'this'.  Dunno why it doesn't die soon after that, but I
suppose your while loop is failing there and hence the thread returns
immediately, and thus joins.

BTW,
>         pthread_mutex_lock(&_mutex);
>         while (_queue->size() == 0 && !_stopped) {
>             pthread_cond_wait(&_condition, &_mutex);
>         }
>         pthread_mutex_unlock(&_mutex);
> 
>         if (_queue->size()>0 && !_stopped) {
>             t=_queue->front();
>             _queue->pop_front();

... is bad.  You'll want to keep the mutex until you've popped the task
off the list.  Then unlock, then go into the following code section.

> Ideas?  Any good online pthreads references/faq's that you'd recommend?

I hear David Butenhof's "Programming with POSIX Threads" is good:
  http://cseng.aw.com/book/0,,0201633922,00.html

More links at: http://www.humanfactor.com/pthreads/

//lat
-- 
Nothing more completely baffles one who is full of
trick and duplicity, than straightforward and simple
integrity in another.  --Charles Caleb Colton

--
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/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: pthread_create -- no callback?
  2001-11-02  0:09 ` Lassi A. Tuura
@ 2001-11-02  4:47   ` Evan Pollan
  2001-11-11  8:26     ` Lassi A. Tuura
  2001-11-11  8:26     ` Evan Pollan
  2001-11-11  8:26   ` Lassi A. Tuura
  1 sibling, 2 replies; 17+ messages in thread
From: Evan Pollan @ 2001-11-02  4:47 UTC (permalink / raw)
  To: Lassi A. Tuura; +Cc: cygwin

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:


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

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

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

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

    pthread_t thread;

    pthread_attr_t pta;
    pthread_attr_init(&pta);

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




The result of this is as follows (again, compiled using g++ on cygwin 1.3.5):

--> pthread_create()
<-- pthread_create()
--> pthread_join()
<-- pthread_join():1


So, the newly created thread fails during it's execution (exit status 1), and
the callback doesn't ever seem to be invoked.  I've tried this both with and
without a pthread_attr_t argument to the pthread_create call.  It still fails,
but with an error code of 168 w/out the pthread_attr_t argument &
initialization code.  Any ideas?


thanks,
Evan

--- "Lassi A. Tuura" <lassi.tuura@cern.ch> wrote:
> > Is there something I'm doing wrong in the pthread_create call?
> 
> Yes, from a very superficial reading at least.
> 
> > void* execute(void* args) {
> 
> Here, you'll want non-zero `args'...
> 
> >     int status = pthread_create(&_thread, NULL, execute, NULL);
> 
> ... and here you are passing null (the last argument).  Since
> QueueProcessor::processTasks is not virtual, you are probably calling it
> with null 'this'.  Dunno why it doesn't die soon after that, but I
> suppose your while loop is failing there and hence the thread returns
> immediately, and thus joins.
> 
> BTW,
> >         pthread_mutex_lock(&_mutex);
> >         while (_queue->size() == 0 && !_stopped) {
> >             pthread_cond_wait(&_condition, &_mutex);
> >         }
> >         pthread_mutex_unlock(&_mutex);
> > 
> >         if (_queue->size()>0 && !_stopped) {
> >             t=_queue->front();
> >             _queue->pop_front();
> 
> ... is bad.  You'll want to keep the mutex until you've popped the task
> off the list.  Then unlock, then go into the following code section.
> 
> > Ideas?  Any good online pthreads references/faq's that you'd recommend?
> 
> I hear David Butenhof's "Programming with POSIX Threads" is good:
>   http://cseng.aw.com/book/0,,0201633922,00.html
> 
> More links at: http://www.humanfactor.com/pthreads/
> 
> //lat
> -- 
> Nothing more completely baffles one who is full of
> trick and duplicity, than straightforward and simple
> integrity in another.  --Charles Caleb Colton
> 
> --
> 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/
> 


__________________________________________________
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/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: pthread_create -- no callback?
  2001-11-11  8:26         ` Lassi A. Tuura
@ 2001-11-11  8:26           ` Robert Collins
  2001-11-11  8:26             ` Evan Pollan
  2001-11-11  8:26           ` Gareth Pearce
  1 sibling, 1 reply; 17+ messages in thread
From: Robert Collins @ 2001-11-11  8:26 UTC (permalink / raw)
  To: Lassi A. Tuura, Evan Pollan; +Cc: cygwin

----- Original Message -----
From: "Lassi A. Tuura" <lassi.tuura@cern.ch>
To: "Evan Pollan" <evan_pollan@yahoo.com>
Cc: <cygwin@cygwin.com>
Sent: Thursday, November 15, 2001 2:28 AM
Subject: Re: pthread_create -- no callback?


> > The sample I included did check the return value of pthread_join.
>
> Nope, you are still not printing pthread_join *return* value -- print
> the int returned by pthread_join as you did with pthread_create.  On
> linux it returns ESRCH = no such thread.  Your problem is with the
> thread argument to pthread_join as shown below.
>
> Since you are not joining with the thread, the output might disappear.
> My guess is that the main thread finishes execution and the stdout
gets
> closed before the second thread executes, and hence you see no output
> from the other thread.  That doesn't happen on linux as you can see
> below, but maybe it is reasonable behaviour on windows.  If you think
it
> is a bug, I am sure cygwin authors would appreciate a patch ;-)

This is indeed the behaviour. The reason is that main() is returning as
opposed to calling pthread_exit (rv);. This is a grey area AFAIK in the
SUSv2 specification.

Patchs accepted as always, probably for gcc in this case.

Rob


--
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/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: pthread_create -- no callback?
  2001-11-11  8:26         ` Lassi A. Tuura
  2001-11-11  8:26           ` Robert Collins
@ 2001-11-11  8:26           ` Gareth Pearce
  2001-11-11  8:26             ` Lassi A. Tuura
  1 sibling, 1 reply; 17+ messages in thread
From: Gareth Pearce @ 2001-11-11  8:26 UTC (permalink / raw)
  To: cygwin


----- Original Message -----
From: "Lassi A. Tuura" <lassi.tuura@cern.ch>
To: "Evan Pollan" <evan_pollan@yahoo.com>
Cc: <cygwin@cygwin.com>
Sent: Thursday, November 15, 2001 2:28 AM
Subject: Re: pthread_create -- no callback?


> > The sample I included did check the return value of pthread_join.
>
> Nope, you are still not printing pthread_join *return* value -- print
> the int returned by pthread_join as you did with pthread_create.  On
> linux it returns ESRCH = no such thread.  Your problem is with the
> thread argument to pthread_join as shown below.
>
> Since you are not joining with the thread, the output might disappear.
> My guess is that the main thread finishes execution and the stdout gets
> closed before the second thread executes, and hence you see no output
> from the other thread.  That doesn't happen on linux as you can see
> below, but maybe it is reasonable behaviour on windows.  If you think it
> is a bug, I am sure cygwin authors would appreciate a patch ;-)
no such thread implies that the thread has already completed execution,
doesnt it?, so therefore the problem would have to be something along the
lines of threads not having their buffers flushed before exiting? - just a
guess
however under cygwin ... if you replace the print statement with a variable
incriment - it doesnt take place either... wish I knew why ... debugging mt
apps is not my idea of fun though ... so I am not about to discover whats
wrong so I can patch it...

*vague though that the thread might not be fully created when pthread_create
returns or something...*

hmm i should sleep instead of posting - probably will look silly in the
morning...
>
> Your code:
> >     void* threadExitStatus;
> >     cout << "--> pthread_join()\n";
> >     pthread_join(&thread, &threadExitStatus);
> >     cout << "<-- pthread_join():" << (int)threadExitStatus << "\n";
>
> Change this to:
>       retVal = pthread_join(&thread, &threadExitStatus);
>       cout << "<-- pthread_join():" << retVal
>            << " " << (int)threadExitStatus << "\n";
>
> I would have expected you to see this in your compilation:
> /tmp/foo.cxx:24: warning: passing `pthread_t *' to argument 1 of
>     `pthread_join(long unsigned int, void **)' lacks a cast
>
> Output with my changes (on linux):
> $ ./a.out
> --> pthread_create()
> <-- pthread_create():0
> --> pthread_join()
> <-- pthread_join():3 1075347592
> --> callbackFunction(0x8048b9b)
> $ grep ESRCH /usr/include/asm/errno.h
> #define ESRCH            3      /* No such process */
>
> HTH,
> //lat
> --
> Those who cannot remember the past are condemned to repeat it.
> --George Santayana
>
> --
> 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/
>
>

--
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/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: pthread_create -- no callback?
  2001-11-11  8:26       ` Evan Pollan
@ 2001-11-11  8:26         ` Lassi A. Tuura
  2001-11-11  8:26           ` Robert Collins
  2001-11-11  8:26           ` Gareth Pearce
  2001-11-11  8:26         ` Gareth Pearce
  1 sibling, 2 replies; 17+ messages in thread
From: Lassi A. Tuura @ 2001-11-11  8:26 UTC (permalink / raw)
  To: Evan Pollan; +Cc: cygwin

> The sample I included did check the return value of pthread_join.

Nope, you are still not printing pthread_join *return* value -- print
the int returned by pthread_join as you did with pthread_create.  On
linux it returns ESRCH = no such thread.  Your problem is with the
thread argument to pthread_join as shown below.

Since you are not joining with the thread, the output might disappear. 
My guess is that the main thread finishes execution and the stdout gets
closed before the second thread executes, and hence you see no output
from the other thread.  That doesn't happen on linux as you can see
below, but maybe it is reasonable behaviour on windows.  If you think it
is a bug, I am sure cygwin authors would appreciate a patch ;-)

Your code:
>     void* threadExitStatus;
>     cout << "--> pthread_join()\n";
>     pthread_join(&thread, &threadExitStatus);
>     cout << "<-- pthread_join():" << (int)threadExitStatus << "\n";

Change this to:
      retVal = pthread_join(&thread, &threadExitStatus);
      cout << "<-- pthread_join():" << retVal
           << " " << (int)threadExitStatus << "\n";

I would have expected you to see this in your compilation:
/tmp/foo.cxx:24: warning: passing `pthread_t *' to argument 1 of
    `pthread_join(long unsigned int, void **)' lacks a cast

Output with my changes (on linux):
$ ./a.out
--> pthread_create()
<-- pthread_create():0
--> pthread_join()
<-- pthread_join():3 1075347592
--> callbackFunction(0x8048b9b)
$ grep ESRCH /usr/include/asm/errno.h 
#define ESRCH            3      /* No such process */

HTH,
//lat
-- 
Those who cannot remember the past are condemned to repeat it.
	--George Santayana

--
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/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: pthread_create -- no callback?
  2001-11-11  8:26           ` Gareth Pearce
@ 2001-11-11  8:26             ` Lassi A. Tuura
  0 siblings, 0 replies; 17+ messages in thread
From: Lassi A. Tuura @ 2001-11-11  8:26 UTC (permalink / raw)
  To: cygwin

> hmm i should sleep instead of posting - probably will look silly in the
> morning...

Yup :-)  Fix the pthread_join usage first, then we'll talk about
limitations in the cygwin implementation.

LOL,
//lat
-- 
In God we Trust -- all others must submit an X.509 certificate.
	--Charles Forsythe

--
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/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: pthread_create -- no callback?
  2001-11-11  8:26           ` Robert Collins
@ 2001-11-11  8:26             ` Evan Pollan
  2001-11-11  8:26               ` Lassi A. Tuura
  0 siblings, 1 reply; 17+ messages in thread
From: Evan Pollan @ 2001-11-11  8:26 UTC (permalink / raw)
  To: Robert Collins, Lassi A. Tuura; +Cc: cygwin

> > On linux it returns ESRCH = no such thread.  Your problem is with the
> > thread argument to pthread_join as shown below.
> >
> > Since you are not joining with the thread, the output might disappear...

I'd missed your point earlier!!!  I was calling pthread_join with the address
of the thread rather than the thread itself...

That's all I needed.  My experience is very stale w/ C & C++, but why didn't I
get at least a compilation warning when I passed the reference to the thread,
rather than its value?

I.e.
    pthread_t thread;
     <snip>
    retVal = pthread_join(thread, &threadExitStatus);

*AND*

    pthread_t thread;
     <snip>
    retVal = pthread_join(&thread, &threadExitStatus);

both compile with no warnings or errors (using g++ -W -Wall
-Wno-non-virtual-dtor -Wwrite-strings -Wpointer-arith -Wnested-externs
-Woverloaded-virtual -Wbad-function-cast -ansi -pedantic).


Evan

__________________________________________________
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/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: pthread_create -- no callback?
  2001-11-02  0:09 ` Lassi A. Tuura
  2001-11-02  4:47   ` Evan Pollan
@ 2001-11-11  8:26   ` Lassi A. Tuura
  1 sibling, 0 replies; 17+ messages in thread
From: Lassi A. Tuura @ 2001-11-11  8:26 UTC (permalink / raw)
  To: Evan Pollan; +Cc: cygwin

> Is there something I'm doing wrong in the pthread_create call?

Yes, from a very superficial reading at least.

> void* execute(void* args) {

Here, you'll want non-zero `args'...

>     int status = pthread_create(&_thread, NULL, execute, NULL);

... and here you are passing null (the last argument).  Since
QueueProcessor::processTasks is not virtual, you are probably calling it
with null 'this'.  Dunno why it doesn't die soon after that, but I
suppose your while loop is failing there and hence the thread returns
immediately, and thus joins.

BTW,
>         pthread_mutex_lock(&_mutex);
>         while (_queue->size() == 0 && !_stopped) {
>             pthread_cond_wait(&_condition, &_mutex);
>         }
>         pthread_mutex_unlock(&_mutex);
> 
>         if (_queue->size()>0 && !_stopped) {
>             t=_queue->front();
>             _queue->pop_front();

... is bad.  You'll want to keep the mutex until you've popped the task
off the list.  Then unlock, then go into the following code section.

> Ideas?  Any good online pthreads references/faq's that you'd recommend?

I hear David Butenhof's "Programming with POSIX Threads" is good:
  http://cseng.aw.com/book/0,,0201633922,00.html

More links at: http://www.humanfactor.com/pthreads/

//lat
-- 
Nothing more completely baffles one who is full of
trick and duplicity, than straightforward and simple
integrity in another.  --Charles Caleb Colton

--
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/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: pthread_create -- no callback?
  2001-11-11  8:26       ` Evan Pollan
  2001-11-11  8:26         ` Lassi A. Tuura
@ 2001-11-11  8:26         ` Gareth Pearce
  2001-11-11  8:26           ` David Starks-Browning
  1 sibling, 1 reply; 17+ messages in thread
From: Gareth Pearce @ 2001-11-11  8:26 UTC (permalink / raw)
  To: cygwin


----- Original Message -----
From: "Evan Pollan" <evan_pollan@yahoo.com>
To: "Lassi A. Tuura" <lassi.tuura@cern.ch>
Cc: <cygwin@cygwin.com>
Sent: Thursday, November 15, 2001 1:18 AM
Subject: Re: pthread_create -- no callback?


> 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?

this time i remember to actually send to the list - that isnt exactly what I
said - the FAQ indicates that pthread_join is not implemented - however a
quick perusal of the source code suggests otherwise. - so I return you to
your guessing... - prehaps the FAQ might update a few of these sometime?

the value your printing out for pthread_join is irrelivent in this case -
since the error is defined by the return value and it returns 3 -
indictating that it couldnt find a process associated witht the thread you
passed it.  I would think this means that the callback has completed...
however it hasnt anyway I fiddle it ... (changing cout for printf ... just
making the function

so I guess I am not much help today... but I thought I should at least
clarify what I had said...

>
> 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" <lassi.tuura@cern.ch> 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/
>
>

--
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/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* pthread_create -- no callback?
  2001-11-01 21:42 pthread_create -- no callback? Evan Pollan
  2001-11-02  0:09 ` Lassi A. Tuura
@ 2001-11-11  8:26 ` Evan Pollan
  1 sibling, 0 replies; 17+ messages in thread
From: Evan Pollan @ 2001-11-11  8:26 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 2574 bytes --]

Thanks for the help inre: getting a linkable pthreads library.  I have
1.3.5 installed and can link (using pthreads, pthread_cond, and pthread_mutex
calls).  However, I can't get pthread_create to call back into my startup
function...

I'm writing a QueueProcessor (producer-consumer pattern) that accepts
implementations of a Task interface.  The QueueProcessor is essentially
a thread pulling Tasks off an STL list + the cond/mutex code to handle the
wait/notify inter-thread communication.

Attached is the source for the QueueProcessor/Task and a test driver.  I've
also attached the output to illustrate the behavior.  Is there something I'm
doing wrong in the pthread_create call?  Notice that none of the messages in
the static driveQueue() call appear, nor anything from
QueueProcessor::processTasks().  The cond/mutex code
QueueProcessor::appendTask() and ::processTasks() is purely conjecture, as I
have no experience w/ POSIX thread wait/notify patterns (too used to the more
OO Java approach).

Ideas?  Any good online pthreads references/faq's that you'd recommend?


regards,
Evan


***
Here's the output:

------------------
QueueProcessor sucessfully constructed.
  --> pthread_create()
  <-- pthread_create()
QueueProcessor started successfully.
  --> joining against the queue thread...
  <-- join() returned...  This shouldn't happen!!!!
Appended Task[TestTask]
Appended Task[TestTask]
Appended Task[TestTask]
Appended Task[TestTask]
Appended Task[TestTask]
Appended Task[TestTask]
Appended Task[TestTask]
Appended Task[TestTask]
Appended Task[TestTask]
Appended Task[TestTask]
QueueProcessor shut down successfully.





--- Robert Collins <robert.collins@itdomain.com.au> wrote:
> From: "Robert Collins" <robert.collins@itdomain.com.au>
> To: "Evan Pollan" <evan_pollan@yahoo.com>,
> 	"Gerrit P. Haase" <cygwin@cygwin.com>
> Subject: Re: Cygwin && C++ POSIX threads support?
> Date: Sun, 11 Nov 2001 15:15:22 +1100
> 
> ----- Original Message -----
> From: "Evan Pollan" <evan_pollan@yahoo.com>
> To: "Gerrit P. Haase" <cygwin@cygwin.com>
> Sent: Sunday, November 11, 2001 3:12 PM
> Subject: Re: Cygwin && C++ POSIX threads support?
> 
> 
> > Great -- I'll pick up the kit tommorow over a more suitable
> > connection.  What's the preferred threading library?  POSIX?  Or
> > something a little more tuned to the Win32 env?
> >
> 
> Just link with no explicit library - the pthreads functions are in libc.
> 
> Rob
> 


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

[-- Attachment #2: QueueProcessor.h --]
[-- Type: text/plain, Size: 1274 bytes --]

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

#define ProcessingException 37

//-----------------------------------------------------------------------
// C-style call to drive the QueueProcessor
//-----------------------------------------------------------------------
extern "C" void* driveQueue (void*);

//-----------------------------------------------------------------------
// Task
//-----------------------------------------------------------------------

class Task {
 public:
    Task () {};

    virtual void execute () throw (int) = 0;

    virtual char* getDescription () {
        return "BaseTask";
    };
    
    friend ostream& operator<< (ostream& stream, Task* t) {
        stream << "Task[" << t->getDescription() << "]";
        return stream;
    };
};

//-----------------------------------------------------------------------
// QueueProcessor
//-----------------------------------------------------------------------

class QueueProcessor {
 private:
    bool _stopped;
    pthread_cond_t _condition;
    pthread_mutex_t _mutex;
    pthread_t _thread;
    list<Task*>* _queue;
    
 public:
    QueueProcessor ();
    ~QueueProcessor ();

    void appendTask (Task*);
    void start ();
    void stop ();
    void processTasks ();
};


[-- Attachment #3: QueueProcessor.cpp --]
[-- Type: text/plain, Size: 3053 bytes --]

#include "QueueProcessor.h"


//-----------------------------------------------------------------------
// C-style call to drive the QueueProcessor
//-----------------------------------------------------------------------

void* execute(void* args) {
    cout << "> Call into driveQueue()\n";
    QueueProcessor* p = (QueueProcessor*)args;
    p->processTasks();
    cout << "< QueueProcessor::processTasks() returned.\n";
    return NULL;
}

//-----------------------------------------------------------------------
// QueueProcessor
//-----------------------------------------------------------------------

QueueProcessor::QueueProcessor () {
    pthread_cond_init(&_condition, NULL);
    pthread_mutex_init(&_mutex, NULL);
    _stopped = false;
    _queue = new list<Task*>();
    cout << "QueueProcessor sucessfully constructed.\n";
}

QueueProcessor::~QueueProcessor () {
    pthread_cond_destroy(&_condition);
    pthread_mutex_destroy(&_mutex);
    delete _queue;
    cout << "QueueProcessor sucessfully destroyed.\n";
}

void QueueProcessor::appendTask (Task* t) {
    if (!_stopped) {

        pthread_mutex_lock(&_mutex);
        _queue->push_back(t);
        pthread_cond_signal(&_condition);
        pthread_mutex_unlock(&_mutex);

        cout << "Appended "<< t << "\n";
    } else {
        cout << "WARNING:  " << t << " added after the QueueProcessor was ";
        cout << "stopped.\n";
    }
}

void QueueProcessor::start () {
    cout << "  --> pthread_create()\n";
    int status = pthread_create(&_thread, NULL, execute, NULL);
    cout << "  <-- pthread_create()\n";

    if (status != 0) {
        cout << "ERROR: Thread creation failed (status=" << status << ").\n";
    } else {
        cout << "QueueProcessor started successfully.\n";
    }

    void* threadExitStatus;
    cout << "  --> joining against the queue thread...\n";
    pthread_join(&_thread, &threadExitStatus);
    cout << "  <-- join() returned...  This shouldn't happen!!!!\n";
}

void QueueProcessor::stop () {
    pthread_mutex_lock(&_mutex);
    _stopped = true;
    pthread_cond_signal(&_condition);
    pthread_mutex_unlock(&_mutex);
    
    void* threadExitStatus;
    pthread_join(&_thread, &threadExitStatus);
    cout << "QueueProcessor shut down successfully.\n";
}

void QueueProcessor::processTasks () {
    cout << "--> processTasks()\n";

    Task* t;
    while (!_stopped) {

        cout << "----> !_stopped\n";
        pthread_mutex_lock(&_mutex);
        while (_queue->size() == 0 && !_stopped) {
            pthread_cond_wait(&_condition, &_mutex);
        }
        pthread_mutex_unlock(&_mutex);

        if (_queue->size()>0 && !_stopped) {
            t=_queue->front();
            _queue->pop_front();
            try {
                t->execute();
            } catch (int i) {
                if (i == ProcessingException) {
                    cout << "Couldn't process "<< t << "\n";
                } else {
                    throw i;
                }
            }
        }
    }
    cout << "<-- processTasks()\n";
}


[-- Attachment #4: Driver.cpp --]
[-- Type: text/plain, Size: 689 bytes --]

#include "QueueProcessor.h"

class TestTask: public Task {
  private:
    int _size;

  public:
    TestTask (int i) {
        _size = i;
    }

    char* getDescription () {
        return "TestTask";
    }

    void execute () {
        cout << "Executing TestTask(" << _size << ")\n";
    }
};

int main (int, char*[]) {

    // Create and startup the QueueProcessor
    QueueProcessor* p = new QueueProcessor();

    p->start();

    // Add the tasks, allowing them to be processed asynchronously by the
    // QueueProcessor
    Task* t;
    for (int i=0; i<10; i++) {
        t = new TestTask(i);
        p->appendTask(t);
    }

    // Shutdown the QueueProcessor
    p->stop();
}


[-- Attachment #5: Type: text/plain, Size: 214 bytes --]

--
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/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: pthread_create -- no callback?
  2001-11-11  8:26             ` Evan Pollan
@ 2001-11-11  8:26               ` Lassi A. Tuura
  2001-11-11  8:26                 ` Robert Collins
  0 siblings, 1 reply; 17+ messages in thread
From: Lassi A. Tuura @ 2001-11-11  8:26 UTC (permalink / raw)
  To: Evan Pollan; +Cc: Robert Collins, cygwin

> That's all I needed.  My experience is very stale w/ C & C++, but why didn't I
> get at least a compilation warning when I passed the reference to the thread,
> rather than its value?

Because pthread_t == void *.  I am sure cygwin team would accept
a patch that consistently uses for example an opaque type[*].  I
suppose it might be a lot of simple-minded editing, but it would
help catch a lot of trivial errors.

But also make it a habit to check all those return values.  That
too will catch many trivial errors.

[*] Like this: `struct __pthread; typedef __pthread *pthread_t;'.
This is all the client side knows about `__pthread', hence it is
opaque.  The struct is defined in the implementation only.  Works
of course only if the implementation really uses structs.  From a
superficial inspection there's a 'pthread' class on cygwin side so
it would work, but I couldn't quite figure out where the code made
the transition from pthread_t == void * to pthread_t == pthread *.

Cheers,
//lat
-- 
Any coward can fight a battle when he's sure of winning; but
give me the man, who has pluck to fight when he's sure of
losing.  That's my way, sir; and there are many victories
worse than a defeat.  --George Eliot

--
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/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: pthread_create -- no callback?
  2001-11-11  8:26         ` Gareth Pearce
@ 2001-11-11  8:26           ` David Starks-Browning
  0 siblings, 0 replies; 17+ messages in thread
From: David Starks-Browning @ 2001-11-11  8:26 UTC (permalink / raw)
  To: cygwin

On Thursday 15 Nov 01, Gareth Pearce writes:
> this time i remember to actually send to the list - that isnt exactly what I
> said - the FAQ indicates that pthread_join is not implemented - however a
> quick perusal of the source code suggests otherwise. - so I return you to
> your guessing... - prehaps the FAQ might update a few of these sometime?

OK.

Thanks,
David


--
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/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: pthread_create -- no callback?
  2001-11-02  4:47   ` Evan Pollan
  2001-11-11  8:26     ` Lassi A. Tuura
@ 2001-11-11  8:26     ` Evan Pollan
  1 sibling, 0 replies; 17+ messages in thread
From: Evan Pollan @ 2001-11-11  8:26 UTC (permalink / raw)
  To: Lassi A. Tuura; +Cc: cygwin

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:


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

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

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

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

    pthread_t thread;

    pthread_attr_t pta;
    pthread_attr_init(&pta);

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




The result of this is as follows (again, compiled using g++ on cygwin 1.3.5):

--> pthread_create()
<-- pthread_create()
--> pthread_join()
<-- pthread_join():1


So, the newly created thread fails during it's execution (exit status 1), and
the callback doesn't ever seem to be invoked.  I've tried this both with and
without a pthread_attr_t argument to the pthread_create call.  It still fails,
but with an error code of 168 w/out the pthread_attr_t argument &
initialization code.  Any ideas?


thanks,
Evan

--- "Lassi A. Tuura" <lassi.tuura@cern.ch> wrote:
> > Is there something I'm doing wrong in the pthread_create call?
> 
> Yes, from a very superficial reading at least.
> 
> > void* execute(void* args) {
> 
> Here, you'll want non-zero `args'...
> 
> >     int status = pthread_create(&_thread, NULL, execute, NULL);
> 
> ... and here you are passing null (the last argument).  Since
> QueueProcessor::processTasks is not virtual, you are probably calling it
> with null 'this'.  Dunno why it doesn't die soon after that, but I
> suppose your while loop is failing there and hence the thread returns
> immediately, and thus joins.
> 
> BTW,
> >         pthread_mutex_lock(&_mutex);
> >         while (_queue->size() == 0 && !_stopped) {
> >             pthread_cond_wait(&_condition, &_mutex);
> >         }
> >         pthread_mutex_unlock(&_mutex);
> > 
> >         if (_queue->size()>0 && !_stopped) {
> >             t=_queue->front();
> >             _queue->pop_front();
> 
> ... is bad.  You'll want to keep the mutex until you've popped the task
> off the list.  Then unlock, then go into the following code section.
> 
> > Ideas?  Any good online pthreads references/faq's that you'd recommend?
> 
> I hear David Butenhof's "Programming with POSIX Threads" is good:
>   http://cseng.aw.com/book/0,,0201633922,00.html
> 
> More links at: http://www.humanfactor.com/pthreads/
> 
> //lat
> -- 
> Nothing more completely baffles one who is full of
> trick and duplicity, than straightforward and simple
> integrity in another.  --Charles Caleb Colton
> 
> --
> 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/
> 


__________________________________________________
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/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: pthread_create -- no callback?
  2001-11-11  8:26     ` Lassi A. Tuura
@ 2001-11-11  8:26       ` Evan Pollan
  2001-11-11  8:26         ` Lassi A. Tuura
  2001-11-11  8:26         ` Gareth Pearce
  0 siblings, 2 replies; 17+ messages in thread
From: Evan Pollan @ 2001-11-11  8:26 UTC (permalink / raw)
  To: Lassi A. Tuura; +Cc: cygwin

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" <lassi.tuura@cern.ch> 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/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: pthread_create -- no callback?
  2001-11-11  8:26               ` Lassi A. Tuura
@ 2001-11-11  8:26                 ` Robert Collins
  0 siblings, 0 replies; 17+ messages in thread
From: Robert Collins @ 2001-11-11  8:26 UTC (permalink / raw)
  To: Lassi A. Tuura, Evan Pollan; +Cc: cygwin


===
----- Original Message -----
From: "Lassi A. Tuura" <lassi.tuura@cern.ch>
To: "Evan Pollan" <evan_pollan@yahoo.com>
Cc: "Robert Collins" <robert.collins@itdomain.com.au>;
<cygwin@cygwin.com>
Sent: Thursday, November 15, 2001 8:02 PM
Subject: Re: pthread_create -- no callback?


> > That's all I needed.  My experience is very stale w/ C & C++, but
why didn't I
> > get at least a compilation warning when I passed the reference to
the thread,
> > rather than its value?
>
> Because pthread_t == void *.  I am sure cygwin team would accept
> a patch that consistently uses for example an opaque type[*].  I
> suppose it might be a lot of simple-minded editing, but it would
> help catch a lot of trivial errors.

Yes, in fact void * was intended to serve the same purpose (as opposed
to a fully defined struct which the prior implementation had.

> [*] Like this: `struct __pthread; typedef __pthread *pthread_t;'.

Thank you. I've put this in my mail archive and will do a patch at some
point - if noone beats me to it that is :].

> This is all the client side knows about `__pthread', hence it is
> opaque.  The struct is defined in the implementation only.  Works
> of course only if the implementation really uses structs.  From a
> superficial inspection there's a 'pthread' class on cygwin side so
> it would work, but I couldn't quite figure out where the code made
> the transition from pthread_t == void * to pthread_t == pthread *.

Inside cygwin,
pthread_t == class pthread **

Rob


--
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/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: pthread_create -- no callback?
  2001-11-02  4:47   ` Evan Pollan
@ 2001-11-11  8:26     ` Lassi A. Tuura
  2001-11-11  8:26       ` Evan Pollan
  2001-11-11  8:26     ` Evan Pollan
  1 sibling, 1 reply; 17+ messages in thread
From: Lassi A. Tuura @ 2001-11-11  8:26 UTC (permalink / raw)
  To: Evan Pollan; +Cc: cygwin

> 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

--
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/

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2001-11-15  9:05 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-01 21:42 pthread_create -- no callback? Evan Pollan
2001-11-02  0:09 ` Lassi A. Tuura
2001-11-02  4:47   ` Evan Pollan
2001-11-11  8:26     ` Lassi A. Tuura
2001-11-11  8:26       ` Evan Pollan
2001-11-11  8:26         ` Lassi A. Tuura
2001-11-11  8:26           ` Robert Collins
2001-11-11  8:26             ` Evan Pollan
2001-11-11  8:26               ` Lassi A. Tuura
2001-11-11  8:26                 ` Robert Collins
2001-11-11  8:26           ` Gareth Pearce
2001-11-11  8:26             ` Lassi A. Tuura
2001-11-11  8:26         ` Gareth Pearce
2001-11-11  8:26           ` David Starks-Browning
2001-11-11  8:26     ` Evan Pollan
2001-11-11  8:26   ` Lassi A. Tuura
2001-11-11  8:26 ` Evan Pollan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).