From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA27928; Wed, 4 Sep 2002 22:43:04 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA27487 for ; Wed, 4 Sep 2002 22:43:03 +0200 (MET DST) Received: from mel-rto2.wanadoo.fr (smtp-out-2.wanadoo.fr [193.252.19.254]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g84Kh3901657 for ; Wed, 4 Sep 2002 22:43:03 +0200 (MET DST) Received: from mel-rta9.wanadoo.fr (193.252.19.69) by mel-rto2.wanadoo.fr (6.5.007) id 3D760C960005C34D for caml-list@inria.fr; Wed, 4 Sep 2002 22:43:02 +0200 Received: from gogol (80.9.109.94) by mel-rta9.wanadoo.fr (6.5.007) id 3D760AD80004C75C for caml-list@inria.fr; Wed, 4 Sep 2002 22:43:02 +0200 Received: from berke by gogol with local (Exim 3.35 #1 (Debian)) id 17mh1o-0002XT-00 for ; Wed, 04 Sep 2002 22:45:32 +0200 Date: Wed, 4 Sep 2002 22:45:31 +0200 From: Berke Durak To: caml-list@inria.fr Subject: [Caml-list] Graphics.wait_next_event () blocks other threads Message-ID: <20020904204531.GC303@gogol> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4i Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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