Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2002-09-04 (20:43)
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 -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

--[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 ()
  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 ()
  let thread1 = Thread.create code1 ()
  and thread2 = Thread.create code2 ()
  while true do
	Thread.yield ()
--[end code]--

This means that :

	1) The graphics module needs to be updated
	2) Native threads should be fixed
	1) A Timeout event type should be added to the Graphics module.
Berke Durak
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: