Process.st
changeset 16047 98326db8c188
parent 15964 ee3faaeb7427
child 16182 44e2baa0f9b8
--- a/Process.st	Sat Feb 15 22:05:57 2014 +0100
+++ b/Process.st	Sun Feb 16 13:15:29 2014 +0100
@@ -2047,6 +2047,11 @@
     "return the value of a thread local variable, or nil if no such variable exists"
 
     ^ self environmentAt:aKey ifAbsent:nil
+
+    "
+     see example in withThreadVariable:boundTo:do:
+
+    "
 !
 
 withThreadVariable:variableNameSymbol boundTo:aValue do:aBlock
@@ -2056,31 +2061,50 @@
     |var oldValue result|
 
     environment isNil ifTrue:[
-	environment := IdentityDictionary new
+        environment := IdentityDictionary new
     ].
     var := environment at:variableNameSymbol ifAbsent:nil.
     var isNil ifTrue:[
-	var := ValueHolder new.
-	environment at:variableNameSymbol put:var.
+        var := ValueHolder new.
+        environment at:variableNameSymbol put:var.
     ].
 
     oldValue := var value.
     [
-	var value:aValue.
-	result := aBlock value.
+        var value:aValue.
+        result := aBlock value.
     ] ensure:[
-	oldValue isNil
-	    ifTrue:[ environment removeKey:variableNameSymbol]
-	    ifFalse:[ var value:oldValue ]
+        oldValue isNil
+            ifTrue:[ environment removeKey:variableNameSymbol]
+            ifFalse:[ var value:oldValue ]
     ].
     ^ result
+
+    "
+     |printIt|
+
+     printIt := [ Transcript showCR:'foo is now ',(Processor activeProcess threadVariableValueOf:#foo) printString ].
+
+     Processor activeProcess
+         withThreadVariable:#foo
+         boundTo:1234
+         do:[
+            printIt value.
+            Processor activeProcess
+                withThreadVariable:#foo
+                boundTo:2345
+                do:[
+                    printIt value
+                ].
+            ]
+    "
 ! !
 
 !Process class methodsFor:'documentation'!
 
 version_CVS
 
-    ^ '$Header: /cvs/stx/stx/libbasic/Process.st,v 1.180 2014-02-05 17:19:20 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Process.st,v 1.181 2014-02-16 12:15:29 cg Exp $'
 !
 
 version_SVN