From: Trevor Jim <tjim@saul.cis.upenn.edu>
To: dsyme@microsoft.com
Cc: caml-list@inria.fr
Subject: Re: threads & OCamlTK
Date: Mon, 22 Mar 1999 13:39:10 -0500 (EST) [thread overview]
Message-ID: <199903221839.NAA20107@saul.cis.upenn.edu> (raw)
In-Reply-To: <39ADCF833E74D111A2D700805F1951EF0F00BA6B@RED-MSG-06> (message from Don Syme on Mon, 15 Mar 1999 07:05:21 -0800)
I've been using camltk with threads for a while. I find it is faster
to run Tk as its own process -- the thread scheduler doesn't seem to
do a good job with Tk involved.
But, if you are running Windows this may not be possible. The Tk
process will need to communicate with the other processes; the most
convenient way to do this is with sockets; and to the best of my
knowledge in Windows it isn't possible to use sockets unless you are
actually plugged in to the network. So, if you want to run on your
Windows laptop, you are stuck with threads.
My program uses one thread to run a Tk gui. I have the gui
periodically poll for input from the other threads. I use channels
and events to do this. Here's a useful function:
let install_poll(poll_function) =
let rec install () =
Timer.add 1 (* Do this every 1 millisecond *)
(fun () ->
(match poll (receive guichannel) with
None -> ()
| Some le -> poll_function [le]);
install() (* After every poll we have to reinstall *)
);
()
in install()
A main thread creates guichannel and all the other threads. The Tk
thread invokes install_poll on a polling function of its choice,
taking input from guichannel. The other threads write to guichannel.
This assumes "open Event".
BTW this doesn't work with bytecode threads. Windows uses native
threads but for Unix systems you may have to install ocaml with a flag
to get native threads. Under Solaris, it works poorly even with
native threads. So, I also use a variant of install_poll to read from
a socket instead of a channel. It's useful when I plug my laptop in
to the network, or when I'm running Unix and I can run the Tk part in
its own process.
Anyone know a better way?
-Trevor
next prev parent reply other threads:[~1999-03-22 19:02 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-03-15 15:05 Don Syme
1999-03-16 17:18 ` Francois Rouaix
1999-03-16 17:42 ` Jun P. Furuse
1999-03-22 18:39 ` Trevor Jim [this message]
1999-03-22 20:04 ` William Chesters
1999-03-23 16:08 ` Xavier Leroy
1999-03-23 15:07 ` Jerome Vouillon
1999-03-24 17:27 ` William Chesters
1999-03-16 17:32 William Chesters
1999-03-17 15:02 Don Syme
1999-03-17 15:57 ` William Chesters
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=199903221839.NAA20107@saul.cis.upenn.edu \
--to=tjim@saul.cis.upenn.edu \
--cc=caml-list@inria.fr \
--cc=dsyme@microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox