From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23731 invoked by alias); 13 Nov 2001 17:29:31 -0000 Mailing-List: contact cygwin-help@sourceware.cygnus.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@sources.redhat.com Received: (qmail 23709 invoked from network); 13 Nov 2001 17:29:28 -0000 Received: from unknown (HELO web21005.mail.yahoo.com) (216.136.227.59) by sourceware.cygnus.com with SMTP; 13 Nov 2001 17:29:28 -0000 Message-ID: <20011113172928.688.qmail@web21005.mail.yahoo.com> Received: from [192.216.181.251] by web21005.mail.yahoo.com via HTTP; Tue, 13 Nov 2001 09:29:28 PST Date: Fri, 02 Nov 2001 04:47:00 -0000 From: Evan Pollan Subject: Re: pthread_create -- no callback? To: "Lassi A. Tuura" Cc: cygwin@cygwin.com In-Reply-To: <3BF13AEE.3CAE1490@cern.ch> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2001-11.t/txt/msg00125.txt 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 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" 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/ From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23731 invoked by alias); 13 Nov 2001 17:29:31 -0000 Mailing-List: contact cygwin-help@sourceware.cygnus.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@sources.redhat.com Received: (qmail 23709 invoked from network); 13 Nov 2001 17:29:28 -0000 Received: from unknown (HELO web21005.mail.yahoo.com) (216.136.227.59) by sourceware.cygnus.com with SMTP; 13 Nov 2001 17:29:28 -0000 Message-ID: <20011113172928.688.qmail@web21005.mail.yahoo.com> Received: from [192.216.181.251] by web21005.mail.yahoo.com via HTTP; Tue, 13 Nov 2001 09:29:28 PST Date: Sun, 11 Nov 2001 08:26:00 -0000 From: Evan Pollan Subject: Re: pthread_create -- no callback? To: "Lassi A. Tuura" Cc: cygwin@cygwin.com In-Reply-To: <3BF13AEE.3CAE1490@cern.ch> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2001-11/txt/msg00125.txt.bz2 Message-ID: <20011111082600.DFbpsSlHw61vDMpIfDezi2RyHmARFRs9_K86Gy_I09o@z> 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 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" 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/