Hi,

The current implementation is not thread safe, when I'm
inside Process>>queueInterrupt: the state of the process
can change. I've added a simple guard to make it safer.

Gwen

>From 9bfeb7de165d3a8612ef113905f28d47e1838bdf Mon Sep 17 00:00:00 2001
From: Gwenael Casaccio <[email protected]>
Date: Sun, 30 Mar 2014 23:24:24 +0200
Subject: [PATCH] kernel: Make Process>> queueInterrupt: atomic.

2014-03-30  Gwenael Casaccio  <[email protected]>

	* kernel/Process.st: Make Process>>queueInterrupt: atomic.
---
 ChangeLog         |  4 ++++
 kernel/Process.st | 28 +++++++++++++++++-----------
 2 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e02e849..62ae7b3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2014-03-30  Gwenael Casaccio  <[email protected]>
+
+	* kernel/Process.st: Make Process>>queueInterrupt: atomic.
+
 2014-03-24  Gwenael Casaccio  <[email protected]>
 
 	* kernel/Process.st: Use the correct namespace in
diff --git a/kernel/Process.st b/kernel/Process.st
index d5931fb..73ce00e 100644
--- a/kernel/Process.st
+++ b/kernel/Process.st
@@ -310,18 +310,24 @@ can suspend themselves and resume themselves however they wish.'>
 			^self].
 		self isTerminated 
 		    ifTrue: [^SystemExceptions.ProcessTerminated signalOn: self].
-		semaphore := myList.
-		suspended := self isReady not.
-		block := suspended
-			    ifFalse: 
-				[self suspend.
-				aBlock]
+                [
+		    semaphore := myList.
+		    suspended := self isReady not.
+		    block := suspended
+			        ifFalse: 
+				    [
+                                      self suspend.
+				      aBlock
+                                    ]
 			    ifTrue: 
-				[semaphore isNil 
-				    ifTrue: [[self evaluate: aBlock ifNotTerminated: [self suspend]]]
-				    ifFalse: [[self evaluate: aBlock ifNotTerminated: [semaphore wait]]]].
-		suspendedContext := block asContext: suspendedContext.
-		self resume]
+				    [
+                                      semaphore isNil 
+				            ifTrue: [ [ self evaluate: aBlock ifNotTerminated: [ self suspend ] ] ]
+				            ifFalse: [ [ self evaluate: aBlock ifNotTerminated: [ semaphore wait ] ] ]
+                                    ].
+		    suspendedContext := block asContext: suspendedContext.
+		    self resume
+                ] valueWithoutPreemption ]
     ]
 
     evaluate: aBlock ifNotTerminated: unwindBlock [
-- 
1.8.3.2

_______________________________________________
help-smalltalk mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/help-smalltalk

Reply via email to