caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Graphics.wait_next_event () blocks other threads
@ 2002-09-04 20:45 Berke Durak
  0 siblings, 0 replies; only message in thread
From: Berke Durak @ 2002-09-04 20:45 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-09-04 20:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-04 20:45 [Caml-list] Graphics.wait_next_event () blocks other threads Berke Durak

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).