curiousity, ensure unwind block priority inheritance

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

curiousity, ensure unwind block priority inheritance

Ben Coman
Just thought I'd share something enlightening I learnt today, a
curious surprise...

When a process is terminated, the #ensure: unwind block effectively
inherits the priority of the terminator process.
Thus the following...
    log := OrderedCollection new.
    s := Semaphore new.
    p :=
    [   [   log add: 1.
           s signal.
           log add: 4.
        ] ensure: [log add: 5]
    ] forkAt: 30.
    s wait.
    log add: 2.
    "p terminate."
    log add: 3.
    100 milliSeconds wait.
    Transcript crShow: log.
...gives {1 2 3 4 5} as expected.

However uncommenting the terminate statement produces {1 2 5 3}.
Quite non-intuitive** to have the "5" code inside the priority 30 block
execute before the "3" code of the priority 40 of the UI/Playground.

**meaning it bit me for a few hours trying to understand some
ProcessTests related to Case 17588.

cheers -ben