Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Berke Durak <durak@liafa.jussieu.fr>
To: caml-list@inria.fr
Subject: [Caml-list] Threads, graphics and timeouts ; functor for multiple windows
Date: Sat, 21 Feb 2004 21:49:40 +0100	[thread overview]
Message-ID: <20040221204940.GA19204@liafa.jussieu.fr> (raw)

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


                 reply	other threads:[~2004-02-21 20:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20040221204940.GA19204@liafa.jussieu.fr \
    --to=durak@liafa.jussieu.fr \
    --cc=caml-list@inria.fr \
    /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