Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Graphics.wait_next_event () blocks other threads
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Berke Durak <berke@a...>
Subject: [Caml-list] Graphics.wait_next_event () blocks other threads
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