class: Monitor
authorClaus Gittinger <cg@exept.de>
Mon, 01 Apr 2013 02:44:18 +0200
changeset 2961 93ab3ea39189
parent 2960 c197b9f70ccf
child 2962 dc468681c480
class: Monitor added: #critical:
Monitor.st
--- a/Monitor.st	Sat Mar 30 02:27:05 2013 +0100
+++ b/Monitor.st	Mon Apr 01 02:44:18 2013 +0200
@@ -9,8 +9,6 @@
  other person.  No title to or ownership of the software is
  hereby transferred.
 "
-
-
 "{ Package: 'stx:libbasic2' }"
 
 Object subclass:#Monitor
@@ -111,6 +109,17 @@
 
 !Monitor methodsFor:'enter & leave'!
 
+critical: aBlock
+    "a critical section. Executes a block as a critical section, secured by the receiver."
+
+    ^ [
+        self enter.
+        aBlock value
+    ] ensure:[
+        self exit
+    ]
+!
+
 enter
     "enter the monitor"
 
@@ -287,5 +296,6 @@
 !Monitor class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/Monitor.st,v 1.16 2002-02-26 13:02:37 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/Monitor.st,v 1.17 2013-04-01 00:44:18 cg Exp $'
 ! !
+