1

How to write a program using Lwt and interacting with a Tk interface. I tried to run the Tk main thread in a Lwt preemptive thread with

let () =
  Lwt.async(Lwt_preemptive.detach Tkthread.thread_main);
  Lwt_main.run(main Tkthread.top)

where main constructs the interface and runs a thread updating it. This ends up in the programming crashing with a fatal error (unable to create widget) and after that, a core dump.

What is the correct way to use Lwt and Labltk together?

Michaël Le Barbier
  • 6,103
  • 5
  • 28
  • 57

1 Answers1

1

I never tried to use LablTk with Lwt, but tkThread.mli clearly says:

Jobs are needed for Windows, as you cannot do GUI work from another thread. This is apparently true on OSX/Aqua too. And even using X11 some calls need to come from the main thread. The basic idea is to either use async (if you don't need a result) or sync whenever you call a Tk related function from another thread (for instance with the threaded toplevel). With sync, beware of deadlocks!

Therefore I propose to wrap your calls of LablTk with TkThread.sync.

You should also ask the question at caml-list. Probably someone there have tried this before.

camlspotter
  • 8,990
  • 23
  • 27