[MLton-user] SMLofNJ.Cont.isolate
Matthew Fluet
fluet at tti-c.org
Fri Apr 25 13:42:17 PDT 2008
On Fri, 25 Apr 2008, Dave Herman wrote:
>> With the MLton.Thread structure (different from the Primitive.MLton.Thread
>> structure referenced in <src>/basis-library/mlton/cont.sml), you could get
>> the behavior of 'throw (isolate f) x' with the following:
>
> Also known as `abort', which is all I really need. :)
If you just need abort, then I would implement it directly in terms of the
MLton.Thread interface, rather than packaging it up as a continuation.
But, to match the SML/NJ interface, you would want to do it as a
continuation.
> Forgive my lack of familiarity with MLton threads... do you just mean this?
>
> let ...
> in
> MLton.Thread.switch (fn _ => r);
> OS.Process.exit ...
> end
No. MLton.Thread.switch is like abort, in that you completely abandon the
current context -- so that OS.Process.exit is never reached. But,
similarly, because you've abandoned all contexts, if the switched-to
computation 'returns' there is no context to receive it. So, we require
the switched-to thread to exit the program (or switch to another thread).
>> And I'm not 100% sure that threads and continuations play nice together,
>> but the above seems fairly benign.
>
> *gulp*
You should be fine, since you are using MLton.Thread as 'thread of
control' rather than as 'multiple threads of control'. Where things would
appear to get tricky is if you capture the continuation in one spawned
thread and then throw to it in another spawned thread, then what "thread"
is the thrown computation?
More information about the MLton-user
mailing list