On 30 January 2015 at 10:24, Anil Madhavapeddy <[email protected]> wrote:
> On 30 Jan 2015, at 10:06, Thomas Leonard <[email protected]> wrote:
>>
>> On 30 January 2015 at 09:30, Anil Madhavapeddy <[email protected]> wrote:
>>> On 29 Jan 2015, at 15:24, Thomas Leonard <[email protected]> wrote:
>>>>
>>>> As part of my continuing mission to break all Mirage APIs, I've
>>>> written up some thoughts on how to improve error handling:
>>>
>>> s/break/fix :-)
>>>
>>>>
>>>> https://github.com/mirage/mirage-www/pull/274
>>>>
>>>> Although written as if it's a final design, it's intended only as a
>>>> starting point for discussion, to find out what we do and don't agree
>>>> on. Please add comments, information about successful approaches
>>>> you've seen, etc.
>>>
>>> This is an excellent writeup. My top-level view is that moving to
>>> an exception-heavier model is fine, but that we really do need to adopt
>>> some sort of Async-style monitor model to make this feasible, so that
>>> exceptions can be contained within a logical section of the code.
>>
>> Doesn't try_lwt (or similar) do this anyway? What particular problem
>> are you worried about?
>>
>
> It does, if used carefully everywhere -- and is quite slow. The
> problem is along the lines of:
>
> Thread 1: try
> Thread 1: <code>
> Thread 1: Lwt.wakeup thread2
> Thread 2: <fast switch to thread2>
> Thread 2: raise Failure
> Thread 1: catch
>
> The fast switch has caused thread 1 to catch the Failure.
Actually, I'm having trouble seeing how this could happen. Lwt should
catch the exception and turn it into a failed thread automatically:
open Lwt
let waiter, waker = Lwt.wait ()
let thread2 =
waiter >>= fun () ->
print_endline "raising Failure";
raise (Failure "Failed")
let () =
print_endline "main start";
begin try Lwt.wakeup waker ();
with Failure _ -> print_endline "caught failure" end;
print_endline "main end"
let () =
Lwt_unix.run thread2
This prints:
main start
raising Failure
main end
Fatal error: exception Failure("Failed")
i.e. the fact that thread2 raised an exception didn't interfere with
the main thread (no "caught failure"), since the main thread didn't
care about the outcome of thead2.
--
Dr Thomas Leonard http://0install.net/
GPG: 9242 9807 C985 3C07 44A6 8B9A AE07 8280 59A5 3CC1
GPG: DA98 25AE CAD0 8975 7CDA BD8E 0713 3F96 CA74 D8BA
_______________________________________________
MirageOS-devel mailing list
[email protected]
http://lists.xenproject.org/cgi-bin/mailman/listinfo/mirageos-devel