Hello, i trying to provide a fix to the issue
http://bugs.squeak.org/view.php?id=6822what is needed to make following code work w/o error:
|sema proc |
sema := Semaphore new.
proc := [ sema wait. self error: 'should not be there' ] fork.
Processor yield.
proc suspend.
proc resume.
The problem here, is that once you issue a #suspend on a process it
puts nil to its myList ivar, ignoring the fact that it could be
waiting on semaphore.
This leads to disconnecting the process from semaphore, and any
subsequent 'sema signal' will be simply lost:
suspend
| oldList |
<primitive: 88> "primitive will fail, if receiver is not active
process, which is just our case"
myList ifNil:[^nil].
oldList := myList.
myList := nil.
oldList remove: self ifAbsent:[].
^oldList
the possible fix would be:
- add an instance variable to Process, say 'semaphore'.
- fix the #suspend to following:
suspend
| oldList |
<primitive: 88> "primitive will fail, if receiver is not active
process, which is just our case"
myList ifNil:[^nil].
oldList := myList.
myList := nil.
oldList remove: self ifAbsent:[].
oldList isKindOf: Semaphore ifTrue: [ semaphore := oldList ].
^oldList
- then, in the #resume
resume
suspendedContext ifNil: [^ self primitiveFailed].
semaphore ifNotNil: [
semaphore resumeWaiting: self.
semaphore := nil.
^ self.
]
^ self primitiveResume
and
Semaphore>>resumeWaiting: aProcess
excessSignals>0
ifTrue: [excessSignals := excessSignals-1.
aProcess primitiveResume. "resume immediately" ]
ifFalse: [self addLastLink: aProcess]
----------
An attached file is the changeset which makes following test to work
w/o failure:
|sema proc bool |
bool := true.
sema := Semaphore new.
proc := [ sema wait. bool ifTrue: [self error: 'should not be there'].
Transcript show: 'semaphore signaled' ] fork.
Processor yield.
proc newSuspend.
proc newResume.
self assert: (sema last == proc).
bool := false.
sema signal.
P.S. i didn't checked how this fix will affect other things around
processes, like mentioned by Mike:
Note that Process>>signalException: (as of in Squeak 3.8, it may be
fixed in later versions?) relies on this broken behaviour.
--
Best regards,
Igor Stasenko AKA sig.
_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project