caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Berke Durak <berke@altern.org>
To: caml-list@inria.fr
Subject: [Caml-list] Graphics.wait_next_event () blocks other threads
Date: Wed, 4 Sep 2002 22:45:31 +0200	[thread overview]
Message-ID: <20020904204531.GC303@gogol> (raw)

Native threads pose serious problems ; since Graphics.wait_next_event does
a simple select (), the bytecode version doesn't work either. So, my original
problem of writing a simple Tetris in Ocaml remains open !

The following code, compiled with
ocamlc -thread unix.cma threads.cma graphics.cma toto.ml -o toto,
should, ideally, on one side, write "alpha 1","alpha 2", etc. to stdout
while still reading keys from the graphics window. This does not
happen.

--[begin code]--
open Thread
open Graphics

let _ =
  open_graph " 300x300";
  let code1 () =
	let x = ref 0 in
	while true do
	  incr x;
	  Printf.printf "alpha %d\n" !x;
	  flush stdout;
	  Thread.yield ()
	done
  in
  let code2 () =
	while true do
	  let st = wait_next_event [Key_pressed] in
	  Printf.printf "key %c pressed...\n" st.key;
	  flush stdout;
	  Thread.yield ()
	done
  in
  let thread1 = Thread.create code1 ()
  and thread2 = Thread.create code2 ()
  in
  while true do
	Thread.yield ()
  done
--[end code]--

This means that :

	1) The graphics module needs to be updated
	2) Native threads should be fixed
or
	1) A Timeout event type should be added to the Graphics module.
--
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:[~2002-09-04 20:43 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=20020904204531.GC303@gogol \
    --to=berke@altern.org \
    --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;
as well as URLs for NNTP newsgroup(s).