[M3devel] pthread_self == null?

Jay K jay.krell at cornell.edu
Mon Jul 26 22:02:44 CEST 2010


Agreed. So agreed with the approximate change?

 - Jay

----------------------------------------
> Subject: Re: [M3devel] pthread_self == null?
> From: hosking at cs.purdue.edu
> Date: Mon, 26 Jul 2010 15:00:29 -0400
> CC: m3devel at elegosoft.com
> To: jay.krell at cornell.edu
>
> The standard doesn't even say that a pthread_t is a pointer.
> It might be an int, in which case 0 might be a valid pthread_t.
>
> On 26 Jul 2010, at 07:18, Jay K wrote:
>
> >
> > I don't see that the standard prohibits NULL from being a valid pthread_t.
> > ?
> > I happened upon this only due to a problem though: OpenBSD x86 4.6 -lX11 -static gives a broken pthreads.
> >
> >
> > We should add an extra boolean to this code, like, before:
> >
> >
> > VAR
> > holder: pthread_t;
> > inCritical := 0;
> >
> > PROCEDURE LockHeap () =
> > VAR self := pthread_self();
> > BEGIN
> > IF pthread_equal(holder, self) = 0 THEN
> > WITH r = pthread_mutex_lock(heapMu) DO <*ASSERT r=0*> END;
> > holder := self;
> > END;
> > INC(inCritical);
> > END LockHeap;
> >
> > PROCEDURE UnlockHeap () =
> > BEGIN
> > <*ASSERT pthread_equal(holder, pthread_self()) # 0*>
> > DEC(inCritical);
> > IF inCritical = 0 THEN
> > holder := NIL;
> > WITH r = pthread_mutex_unlock(heapMu) DO <*ASSERT r=0*> END;
> > END;
> > END UnlockHeap;
> >
> >
> >
> > after:
> >
> > VAR
> > holder: pthread_t;
> > + holder_valid: BOOLEAN;
> > inCritical := 0;
> >
> > PROCEDURE LockHeap () =
> > VAR self := pthread_self();
> > BEGIN
> > * IF NOT holder_valid OR pthread_equal(holder, self) = 0 THEN
> > WITH r = pthread_mutex_lock(heapMu) DO <*ASSERT r=0*> END;
> > holder := self;
> > + holder_valid := TRUE;
> > END;
> > INC(inCritical);
> > END LockHeap;
> >
> > PROCEDURE UnlockHeap () =
> > BEGIN
> > * <*ASSERT holder_valid AND pthread_equal(holder, pthread_self()) # 0*>
> > DEC(inCritical);
> > IF inCritical = 0 THEN
> > holder := NIL;
> > + holder_valid := FALSE
> >
> > WITH r = pthread_mutex_unlock(heapMu) DO <*ASSERT r=0*> END;
> > END;
> > END UnlockHeap;
> >
> >
> > I think so.
> >
> >
> > - Jay
> >
> >
>
 		 	   		  


More information about the M3devel mailing list