jaked / lwt-equeue

Run Lwt code on top of Ocamlnet's Equeue
10 stars 4 forks source link

lwt-equeue does not run the ocamlnet event queue #1

Closed hansole closed 14 years ago

hansole commented 14 years ago

Seems like the current version of lwt-equeue does not run threads at top of ocamlnet This program works at older version 0.2.1 of orpc but not with the trunk of lwt-equeue. (Note that the old version is also using ocaml 3.11.1 and the new version is running using 3.12, but I guess that is not the cause of the problem): open Lwt let rec do_something () = Lwtunix.sleep 1.0 >>= fun -> Printf.printf "*%!"; do_something ()

let esys = Unixqueue.create_unix_eventsystem ();; let = Lwt_equeue.set_event_system esys; ignore(do_something ()); Unixqueue.run esys; ;;

I'm able to run Lwt threads that are linked agains lwt-equeue with the latest version by running them as lwt thread: open Lwt

let rec do_something () = Lwtunix.sleep 1.0 >>= fun -> Printf.printf "*%!"; do_something ()

let esys = Unixqueue.create_unix_eventsystem ();; let = Lwt_equeue.set_event_system esys; Lwt_unix.run (do_something ()); ;;

And this can be done without creating or setting the event system, so I guess they are run fully outside ocamlnet. tags: <.ml_> : pkg_lwt-equeue <*.byte> : pkg_lwt-equeue

Also I got a problem when compiling lwt-equeue the first time. It wants to compile cohttpserver-netplex that is dependent on lwt-equeue which is not yet installed.

jaked commented 14 years ago

Thank you for the bug reports.

I just pushed a fix for the build issue with cohttpserver. It will still fail if you don't have cohttpserver; I need to add a configure script.

On the issue with your thread not running: your second example is correct---you should call Lwt_main.run (Lwt_unix.run is an alias of this) instead of Unixqueue.run. If you don't link Lwt_equeue you get the default Lwt scheduler, which is why your example still runs if you don't set the event system.

If you are running under a pre-existing event system (e.g. you are running under Netplex) then you shouldn't call Lwt_main.run, since there is already a top-level call to Unixqueue.run active. Instead you should use Lwt_equeue.start to launch your main thread. The reason for this (and the reason you need Lwt_main.run instead of Unixqueue.run above) is that we need to register the active events (file descriptors and timeouts) with the event system before running it.

I will write some documentation for Lwt_equeue explaining this.

hansole commented 14 years ago

The Lwt_equeue.start seems to do the trick. At least for the test example. I'll try to do the changes to my actual application.

Thanks