Monitor.st
changeset 599 83af18019cc9
parent 560 feae8d3ae643
child 642 53c27655489b
--- a/Monitor.st	Tue Dec 23 16:31:49 1997 +0100
+++ b/Monitor.st	Mon Jan 12 14:24:52 1998 +0100
@@ -1,6 +1,6 @@
 "
  COPYRIGHT (c) 1996 by Claus Gittinger
-              All Rights Reserved
+	      All Rights Reserved
 
  This software is furnished under a license and may be used
  only in accordance with the terms of that license and with the
@@ -23,7 +23,7 @@
 copyright
 "
  COPYRIGHT (c) 1996 by Claus Gittinger
-              All Rights Reserved
+	      All Rights Reserved
 
  This software is furnished under a license and may be used
  only in accordance with the terms of that license and with the
@@ -44,58 +44,58 @@
     You have to care for unwinds yourself.
 
     Notice:
-        This is an experimental demo class - there is no WARRANTY.
-        Smalltalkers should use Semaphores and RecursionLocks, which
-        are unwind-save.
+	This is an experimental demo class - there is no WARRANTY.
+	Smalltalkers should use Semaphores and RecursionLocks, which
+	are unwind-save.
 
     [see also:]
-        RecursionLock Semaphore Delay SharedQueue
-        Block
+	RecursionLock Semaphore Delay SharedQueue
+	Block
 
     [author:]
-        Claus Gittinger
+	Claus Gittinger
 "
 
 !
 
 examples
 "
-        |mon p1 p2 p3|
+	|mon p1 p2 p3|
 
-        mon := Monitor new.
+	mon := Monitor new.
 
-        p1 := [
-             10 timesRepeat:[
-                 Delay waitForSeconds:0.3.
-                 mon enter.
-                 'p1 got it' printNL.
-                 Delay waitForSeconds:0.3.
-                 'p1 leaves' printNL.
-                 mon exit
-             ]
-        ] fork.
+	p1 := [
+	     10 timesRepeat:[
+		 Delay waitForSeconds:0.3.
+		 mon enter.
+		 'p1 got it' printNL.
+		 Delay waitForSeconds:0.3.
+		 'p1 leaves' printNL.
+		 mon exit
+	     ]
+	] fork.
 
-        p2 := [
-             20 timesRepeat:[
-                 Delay waitForSeconds:0.2.
-                 mon enter.
-                 'p2 got it' printNL.
-                 Delay waitForSeconds:0.2.
-                 'p2 leaves' printNL.
-                 mon exit
-             ]
-        ] fork.
+	p2 := [
+	     20 timesRepeat:[
+		 Delay waitForSeconds:0.2.
+		 mon enter.
+		 'p2 got it' printNL.
+		 Delay waitForSeconds:0.2.
+		 'p2 leaves' printNL.
+		 mon exit
+	     ]
+	] fork.
 
-        p3 := [
-             30 timesRepeat:[
-                 Delay waitForSeconds:0.1.
-                 mon enter.
-                 'p3 got it' printNL.
-                 Delay waitForSeconds:0.1.
-                 'p3 leaves' printNL.
-                 mon exit
-             ]
-        ] fork.
+	p3 := [
+	     30 timesRepeat:[
+		 Delay waitForSeconds:0.1.
+		 mon enter.
+		 'p3 got it' printNL.
+		 Delay waitForSeconds:0.1.
+		 'p3 leaves' printNL.
+		 mon exit
+	     ]
+	] fork.
 
 
 "
@@ -123,29 +123,36 @@
      go mad ... (especially be careful when adding a debugPrint-here)
     "
     owningProcess isNil ifTrue:[
-        count := 1.
-        owningProcess := thisProcess.
-        ^ self
+	count := 1.
+	owningProcess := thisProcess.
+	^ self
     ].
 
     owningProcess == thisProcess ifTrue:[
-        count := count + 1.
-        ^ self
+	count := count + 1.
+	^ self
+    ].
+
+    owningProcess isDead ifTrue:[
+	self halt.
+	owningProcess := thisProcess.
+	count := 1.
+	^ self
     ].
 
     wasBlocked := OperatingSystem blockInterrupts.
     [
-        [owningProcess notNil] whileTrue:[
-            thisProcess state:#monWait.
-            sema wait.
-        ].
-        count := 1.
-        owningProcess := thisProcess.
+	[owningProcess notNil] whileTrue:[
+	    thisProcess state:#monWait.
+	    sema wait.
+	].
+	count := 1.
+	owningProcess := thisProcess.
     ] valueOnUnwindDo:[
-        wasBlocked ifFalse:[OperatingSystem unblockInterrupts]
+	wasBlocked ifFalse:[OperatingSystem unblockInterrupts]
     ]
 
-    "Modified: 27.6.1996 / 16:46:40 / cg"
+    "Modified: / 8.1.1998 / 17:40:22 / cg"
 !
 
 exit
@@ -154,8 +161,8 @@
     |thisProcess|
 
     count == 0 ifTrue:[
-        'MONITOR [info]: already left' errorPrintCR.
-        ^ self
+	'MONITOR [info]: already left' errorPrintCR.
+	^ self
     ].
 
     thisProcess := Processor activeProcess.
@@ -167,7 +174,7 @@
      go mad ... (especially be careful when adding a debugPrint-here)
     "
     owningProcess ~~ thisProcess ifTrue:[
-        self halt:'invalid exit'
+	self halt:'invalid exit'
     ].
 
     count := count - 1.
@@ -200,9 +207,9 @@
 
     wasBlocked := OperatingSystem blockInterrupts.
     owningProcess notNil ifTrue:[
-        ret := false
+	ret := false
     ] ifFalse:[
-        sema numberOfWaitingProcesses ~~ 0 ifTrue:[ret := false].
+	sema numberOfWaitingProcesses ~~ 0 ifTrue:[ret := false].
     ].
     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
     ^ ret.
@@ -213,5 +220,5 @@
 !Monitor class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/Monitor.st,v 1.7 1997-08-21 14:44:34 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/Monitor.st,v 1.8 1998-01-12 13:24:52 cg Exp $'
 ! !