From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.3 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST autolearn=disabled version=3.1.3 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id AB086BC6B for ; Sun, 11 Nov 2007 00:00:01 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAM3GNUfAXQImh2dsb2JhbACBW40nAQEBCAop X-IronPort-AV: E=Sophos;i="4.21,399,1188770400"; d="scan'208";a="19150062" Received: from discorde.inria.fr ([192.93.2.38]) by mail4-smtp-sop.national.inria.fr with ESMTP; 11 Nov 2007 00:00:01 +0100 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id lAAN003Z024968 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Sun, 11 Nov 2007 00:00:01 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAM3GNUdQDPIahWdsb2JhbACBW40nAQEBCAQGBwgTBw X-IronPort-AV: E=Sophos;i="4.21,399,1188770400"; d="scan'208";a="19150061" Received: from smtp20.orange.fr ([80.12.242.26]) by mail4-smtp-sop.national.inria.fr with ESMTP; 11 Nov 2007 00:00:00 +0100 Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf2002.orange.fr (SMTP Server) with ESMTP id 268AC1C0008C for ; Sun, 11 Nov 2007 00:00:00 +0100 (CET) Received: from localhost.localdomain (Mix-Lyon-303-3-238.w193-248.abo.wanadoo.fr [193.248.105.238]) by mwinf2002.orange.fr (SMTP Server) with ESMTP id 323511C00088 for ; Sat, 10 Nov 2007 23:59:59 +0100 (CET) X-ME-UUID: 20071110225959205.323511C00088@mwinf2002.orange.fr Date: Sat, 10 Nov 2007 23:01:45 +0100 From: Fabrice Marchant To: caml-list@inria.fr Subject: Why 'Graphics.wait_next_event' doesn't reply anymore ? Message-ID: <20071110230145.3aebafe4@localhost.localdomain> X-Mailer: Claws Mail 2.10.0 (GTK+ 2.10.13; i486-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 473637F0.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; printf:01 arises:01 0.01:98 threads:01 rec:01 short:01 none':97 match:02 match:02 graphics:02 graphics:02 seems:03 let:03 let:03 problem:05 Hi ! This issue with 'Graphics.wait_next_event' seems only to happen in some cases with threads. Please consider the code snippet below : --------------------------------------------------- let id = ref None let run () = while !id <> None do step (); (* Changes drawing state *) plot () (* ; Thread.delay 0.01 *) done let rec test () = print "Graphics.wait_next_event, next statement...\n"; (* A flushed printf *) let status = wait_next_event [ Key_pressed ] in print "Graphics.wait_next_event returned.\n"; match status.key with 'r' -> (match !id with None -> id := Some (Thread.create run ()) | Some _ -> ()); test () | 's' -> id := None; test () | _ -> () ----------------------------------------------- First time you press 'r', a thread is created. ( There is no delay problem in changing thread 'id' after creation and process test '!id <> None' is soon true at first call. ) So the thread does its animation job. Here is the full short - stuck - test code : http://fabrice.marchant.free.fr/code/wait_next_event/ After the thread is launched, we can check the console to state that the "main" thread is waiting for a key press. The issue arises now. You can hit any key : 'Graphics.wait_next_event' couldn't care less. Please why ? Another thing I do not understand : if you insert a delay inside the 'run' thread code loop ( please see uncommentable Thread.delay above ), the program does not stick anymore, 'Graphics.wait_next_event' normally listening to the keyboard. ( Nice, but my aim was to run this thread at full speed... ) Thanks, Fabrice