Subject: Re: pthread_create -- no callback?
From: "Lassi A. Tuura" <[email-masked]>
To: Evan Pollan <[email-masked]>
Cc: [email-masked]
Date: Tue, 13 Nov 2001 16:23:26 +0100

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