On 05 Jan 2016, at 7:24 , Denis Kudriashov <dionisiydk@gmail.com> wrote:


2016-01-05 18:49 GMT+01:00 Henrik Johansen <henrik.s.johansen@veloxit.no>:
ifCurtailed: only unwinds if an error/termination occured, so that would mean not signalling the semaphore when everything goes as planned, and we leave the critical section...

I not suppose to replace #ensure: with #ifCurtailed:. I think about:

signalRequired := false.
[
[signalRequired := true.
self wait] ifCurtailed: [signalRequired := false].
blockValue := mutuallyExcludedBlock value
] ensure: [signalRequired ifTrue: [self signal]].
^blockValue


Ah, that makes more sense, yes, much simpler than what I wrote!
AFAICT, it should work too ;)

+1 from me for fixing Mutex to work under termination, change current Semaphore >> critical: users, and deprecating Semaphore >> #critical: ,after changing it to use ifCurtailed: as you suggested and removing the special casing from Process >> #terminate.

Cheers,
Henry