Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Q] inter_process communication in CamlTk,OCaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Q] inter_process communication in CamlTk,OCaml
From: Bomshik Kim <bskim@ropas.kaist.ac.kr>

> Now I'm making some application with CamlTk and OCaml.
> Problem is how to communicate between GUI part and Working part.
> 
> In GUI part, there are start_work button, and stop_work button.
> The work is started in a new_process (by fork) by clicking 
> start_work button. But the work may take a long time 
> (let's assume 10 min) and raise an exception. 
> and I want to make the result of work shown on GUI Text.
> So GUI part should receive the result from Work part.

You might consider using threads. The idea is that you have a main
thread running the Tk main loop, and worker threads started by it.
They may communicate through mutex or events.

CamlTk is not thread safe, so you must be careful about not using any
Tk command in your worker threads, since they may cause race
conditions. Also, this will not work with bytecode threads (the
default) since you won't be able to switch threads once inside the
main loop. You have to compile Caml with posix threads instead.

I'm no expert in thread programming, so I'm not sure whether what I'm
doing is really safe, but this is actually the way the ocamlbrowser
subshell works under windows, using a worker thread to read from a
pipe (file labltk/browser/shell.ml).

Jacques
---------------------------------------------------------------------------
Jacques Garrigue      Kyoto University     garrigue at kurims.kyoto-u.ac.jp
		<A HREF=http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/>JG</A>