Hi
  I had tried this program on Rh5.2 and on Sun Solaris 2.6. On RH5.2 it gives
seg violation and give some internal table overflow in solaris.
.  One problem I can definitely spot in the program is in Implementing
Asynchronous cancellation. Even the Posix standards claim that the for Async
cancellation,
   thread can  come out any time, even from the middle of an instruction.
  That means you can come out of the middle of "pthread_mutex_lock"  which can
leave your program in a hanging state.
  What I can suggest is
      1)  Redesign your application to Avoid Asynchronous canceling. ( I never
use Async canceling )

       if Async canceling is absolutely must then
      1)  Ensure that before thread exits it releases the mutex.  For this use
"pthread_cleanup_push "  and "pthread_cleanup_pop"
      2)  Ensure that cancellation does not occur during "pthread_mutex_lock"
for this use "pthread_setcancelstate".


Now the problem that why program behaves differently in RH4.1, 5.2 and 6.0.
Honestly I doent know the precise answer, what I strongly feel is that for newer
kernels the OS level calls from the api "pthread_mutex_lock" are implemented in
ASYNC CANCELLATION SAFE mode ( Just a guess as I am still on 2.0.36 ).  Which
prevents cancellation from middle of the call hence avoiding hanging states.

You can refer to David R. Butenhof's Book (Chap 5 ) for more details.

Hope this Helps.
Regards
Nitin


"Guruprasad, Mahendrakar V (IE10)" wrote:

> Hi,
>         Thanks. at last I got a helping hand. This following code will cause
> seg faults in RedHat4.2  as well as in 5.1.
>         But it didn't cause seg faults in redHat 6.0
>
>         I seems that detaching or joining a thread after killing its waiting
> on mutex/cond variable
>          causes seg faults. This problem is over come in
>         6.0. This similar kind of problem is screwing up my project which is
> based on RedHat 4.2 linux
>         Expecting your reply
> Bye
>
> #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]);
>                 }
>         }
> }
>
> > -----Original Message-----
> > From: Nitin [SMTP:[EMAIL PROTECTED]]
> > Sent: Thursday, September 23, 1999 11:30 AM
> > To:   [EMAIL PROTECTED]
> > Subject:      Re: [LI] Please Respond
> >
> > I am  using pthreads on RH 5.2 Not yet tried on RH 6.0. If you can
> > describe your
> > programes or send the code I may be able to help.
> >
> > Nitin
> >
> > "Guruprasad, Mahendrakar V (IE10)" wrote:
> >
> > > Queries are not being answered
> > >
> > > > Hi all,
> > > >       I have some problems with using pthread library. When I link  my
> > > > code with pthread library
> > > >       in RedHat 4.2 (Even in RedHat 5.1) & execute, its causing some
> > > > undesirable results. But
> > > >       when I link same code with pthread library in RedHat6.0 & run,
> > it
> > > > works perfectly. I feel there is
> > > >       version problem with pthreadlibrary & I think they have fixed
> > these
> > > > problems in the newer version.
> > > >       What should I do?? Is it possible to install this version of
> > pthread
> > > > library from  redHat 6.0 to 4.2??
> > > >       Please reply.
> > > >
> > > > GURUPRASAD V.M.
> > > > Honeywell India Software Operations
> > > >
> > > >
> > > >
> > > >
> > > > --------------------------------------------------------------------
> > > > 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.
> > > --------------------------------------------------------------------
> > > 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.

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

Reply via email to