[M3devel] pthread_self == null?
    Jay K 
    jay.krell at cornell.edu
       
    Mon Jul 26 13:18:26 CEST 2010
    
    
  
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