Browse thread
[Caml-list] Threads, graphics and timeouts ; functor for multiple windows
- Berke Durak
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Berke Durak <durak@l...> |
| Subject: | [Caml-list] Threads, graphics and timeouts ; functor for multiple windows |
Hello everyone,
Last year I was writing some Tetris® clone in Ocaml using the graphics
library... I had to patch the graphics library to include a Timeout
event, because it wouldn't work with threads.
I've tried again yesterday with 3.07.
Basically, whatever I do I get "interrupted system call select" errors.
Today, the graphics library still doesn't work with threads. I have
tried both bytecode scheduling and pthreads.
I would like to make programs that work as follows :
while true do
let t = compute_timeout () in
match wait_for_keypress_or_timeout t with
| Timeout -> do_something
| Keypress k -> do_something else
done
I've tried with threads, using a "ticker" thread that communicated with
the main thread via events. It didn't work because there is no timeout
event ; and even if the timer thread sends a signal every second, I
get the "interrupted system call select" error (particularly when the
system load increases).
I then used a Unix pipe with timed_read. Same problem.
Is there a way to write a (graphical) Tetris with Ocaml with the
Graphics library ?
I'd like to make a few wild suggestions :
- In the Event module :
- Add a timeout event
- Provide a mechanism for aborting events
- Or add a timed wait function
- In the Graphics library :
- Fix the issues with threads
- Include a timeout event (see my patch at
http://www.liafa.jussieu.fr/~durak/)
Another suggestion to provide for multiple windows in graphics :
module type WINDOW_ID =
sig
val id : int
end
module Builder(W:WINDOW_ID) : GRAPHICS_MODULE
Ie to have multiple windows (say two) you'd just have to make :
let G1 = Graphics.Builder(struct let id = 1 end) in
let G2 = Graphics.Builder(struct let id = 2 end) in
G1.open_window " 100x30";
G2.open_window " 100x50";
G1.moveto 0 0; G1.draw_string "this is window 1";
G2.moveto 0 0; G2.draw_string "this is window 1"
--
Berke Durak
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners