Oberon Community Platform Forum

Development => Bug Report => Topic started by: alys on March 19, 2008, 10:45:27 PM



Title: Active oberon paper - is it correct?
Post by: alys on March 19, 2008, 10:45:27 PM
in paper I found -
http://bluebottle.ethz.ch/languagereport/node8.html#SECTION00084000000000000000 (http://bluebottle.ethz.ch/languagereport/node8.html#SECTION00084000000000000000)
method unlock of this obect is not completely correct. or no?

  ReentrantLock* = OBJECT
    VAR
      lockedBy: PTR;
      depth: LONGINT;
   
    PROCEDURE Lock*;
    VAR  me: PTR;
    BEGIN {EXCLUSIVE}
      me := AosActive.CurrentThread();
      AWAIT((lockedBy = NIL) OR (lockedBy = me));
      lockedBy := me;
      INC(depth)
    END Lock;
   
    PROCEDURE Unlock*;
    BEGIN {EXCLUSIVE}
      (*might should be added?*)
     IF lockedBy#AosActive.CurrentThread() THEN Error("...."); RETURN; END;
      IF lockedBy=NIL THEN Error("..."); RETURN; END;
      (*original text*)
      DEC(depth);
      IF depth = 0 THEN lockedBy := NIL END
    END Unlock;
   
  END ReentrantLock;

else any thread can unlock any lock??


Title: Re: Active oberon paper - is it correct?
Post by: staubesv on March 20, 2008, 09:00:58 AM
This depends on what you consider correct: This implementation assumes the Unlock is only called by threads that successfully acquired the lock. But you're right: Any other thread could call Unlock without having acquired the lock.

The implementation of re-rentrant locks used in AOS (Locks.RecursiveLock) does the check, however.