[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]
RE: [LI] Please Respond
Hi,
Thanks for your reply. I am confused with your 1 st observation. My
intention in that program is
to cancel the created threads & not the calling thread. If you do
pthread_exit(PTHREAD_CANCELED)
then the calling thread will be cancelled. I don't want that. I want
to cancel the created threads
your 3rd observation is true. That is what I am emphasizing. If a
threads waiting on same mutex/cond variable
are cancelled, & then the resources held by them can't be
deallocated. If we deallocate ,
we will be screwed up in RedHat5.1, but not in RedHat6.0
Bye
> -----Original Message-----
> From: sudheer@xxxxxxxxxxxxx [SMTP:sudheer@xxxxxxxxxxxxx]
> Sent: Thursday, September 23, 1999 3:44 PM
> To: Guruprasad, Mahendrakar V (IE10)
> Subject: RE: [LI] Please Respond
>
> Hi ,
>
> I'm using SuSE-5.1, and i don't know much about programming using
> threads. Still, i would like to send some of my observations in
> hope that it may be useful(unless a guru comes out with all
> possible reasons)
>
> 1) In your program you use the flag "PTHREAD_CANCEL_ASYNCHRONOUS" for
> immediate consideration of cancel request. Hence, instead of calling
> pthread_cancel(pThread[i]); if pthread_exit(PTHREAD_CANCELED); is used,
> it doesn't dump core, also it's cancelling the calling thread.
>
> 2) When i tried PTHREAD_CANCEL_DEFERRED, in place of
> PTHREAD_CANCEL_ASYNCHRONOUS, then also the program didn't crash.
>
> 3) Everythings seems to be hanging around the mutex lock.
>
> sudheer
>
>
> On Thu, 23 Sep 1999, Guruprasad, Mahendrakar V (IE10) wrote:
>
> > Hi,
> > Thanks. at last I got a helping hand. This following code will cause
> >
> >
> > #include <stdio.h>
> > #include <pthread.h>
> > #include <stdlib.h>
> > pthread_mutex_t mutex=PTHREAD_MUTEX_INITIALIZER;
> > void * thread(void *buf)
> > {
> > pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,NULL);
> > pthread_mutex_lock(&mutex);
> > while(1);
> > }
> > void main(void)
> > {
> > void fun(void);
> > for(;;)
> > fun();
> > }
> >
> > void fun(void)
> > {
> > pthread_t *pThread;
> > int i;
> > int nCount=6;
> > int wCounter = 0;
> > pThread=(pthread_t *)malloc(nCount*sizeof(pthread_t));
> > for(;;)
> > {
> > wCounter++;
> > if (wCounter % 100 == 0)
> > printf("Starting Threads Loop #%d.\n", wCounter);
> >
> > for(i=0;i<nCount;i++)
> > pthread_create(&pThread[i],NULL,thread,NULL);
> >
> > for(i=0;i<nCount;i++)
> > {
> > pthread_cancel(pThread[i]);
> > // pthread_join(pThread[i],NULL);
> > pthread_detach(pThread[i]);
> > }
> > }
> > }
> >
> >
- --------------------------------------------------------------------
For more information on Linux in India visit http://www.linux-india.org/
The Linux India mailing list does not accept postings in HTML format.
------------------------------