Threading woes

Jon Harrop <[email protected]> Sat, 6 Feb 2010 05:30:16 +0000
Newsgroups gmane.comp.lang.ocaml.lib.gtk
Organization Flying Frog Consultancy Ltd.
Message-ID <[email protected]>
I'm trying to write a program that uses a UI thread for visualization and a 
worker thread to do computation. I had the problem that my worker thread was 
being blocked by something, preventing it from running. Digging, I discovered 
that LablGTK requires the use of a different "main" in the case of threaded 
code.

I believe you are either supposed to compile GtkThInit.cmx into your project 
or copy its code:

  let thread = GtkThread.start ()

Judging by examples/GL/simple_th.ml:

  ...
  GtkThread.async w#show ();
  Thread.join GtkThInit.thread

I'd say the GtkThread.start function was spawning a separate UI thread. So 
I've changed my code to:

  window#show();
  Thread.join(GtkThread.start ());

and am compiling with:

  ocamlopt -annot -thread -I +lablgtk2 -I +lablgtkgl2 -I +lablgl lablgl.cmxa 
lablgtk.cmxa lablgtkgl.cmxa unix.cmxa threads.cmxa gtkThread.cmx x.ml -o x

but when I run the resulting program I get a segfault:

  $ ./x

  (process:15948): GLib-GObject-WARNING **: invalid (NULL) pointer instance

  (process:15948): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion
  `G_TYPE_CHECK_INSTANCE (instance)' failed
  Segmentation fault

What am I doing wrong?

-- 
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e