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=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 0A5FFBC69 for ; Sun, 11 Nov 2007 17:48:36 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAA7BNkfAbSoIh2dsb2JhbACPBAEBAQgKKQ X-IronPort-AV: E=Sophos;i="4.21,402,1188770400"; d="scan'208";a="5675112" Received: from einhorn.in-berlin.de ([192.109.42.8]) by mail3-smtp-sop.national.inria.fr with ESMTP; 11 Nov 2007 17:48:35 +0100 X-Envelope-From: oliver@first.in-berlin.de X-Envelope-To: Received: from einhorn.in-berlin.de (localhost [127.0.0.1]) by einhorn.in-berlin.de (8.13.6/8.13.6/Debian-1) with ESMTP id lABGmYMM020960 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Sun, 11 Nov 2007 17:48:34 +0100 Received: (from www-data@localhost) by einhorn.in-berlin.de (8.13.6/8.13.6/Submit) id lABGmYG1020955 for caml-list@yquem.inria.fr; Sun, 11 Nov 2007 17:48:34 +0100 X-Authentication-Warning: einhorn.in-berlin.de: www-data set sender to oliver@first.in-berlin.de using -f Received: from dslb-088-073-093-214.pools.arcor-ip.net (dslb-088-073-093-214.pools.arcor-ip.net [88.73.93.214]) by webmail.in-berlin.de (IMP) with HTTP for ; Sun, 11 Nov 2007 17:48:34 +0100 Message-ID: <1194799714.473732620f33e@webmail.in-berlin.de> Date: Sun, 11 Nov 2007 17:48:34 +0100 From: Oliver Bandel To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Why 'Graphics.wait_next_event' doesn't reply anymore ? References: <20071110230145.3aebafe4@localhost.localdomain> <20071111150720.4f8d1c44@localhost.localdomain> In-Reply-To: <20071111150720.4f8d1c44@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: Internet Messaging Program (IMP) 3.2.6 X-Scanned-By: MIMEDefang_at_IN-Berlin_e.V. on 192.109.42.8 X-Spam: no; 0.00; bandel:01 in-berlin:01 threading:01 scheduler:01 printf:01 printf:01 stdout:01 stdout:01 threads:01 oliver:01 oliver:01 graph:01 caml-list:01 caml-list:01 caml:02 Hi, Zitat von Fabrice Marchant : > Replying to myself : > > Found this 2002 - unanswered ... thread - : "Graphics.wait_next_event () > blocks other threads" > http://caml.inria.fr/pub/ml-archives/caml-list/2002/09/d29ca3379fe68e3cdbd36323f5f409c0.en.html > [...] This code looks ugly. Why? I don't mean the indentation and not the use of names... ... I mean the way, how it handles the threading. It forces calls to the scheduler all too often. And it does it at three places. And in the print-loop it clals it every time! This is the way of wasting ressources. I have rewritten it, but not the time to explain it now, in some minutes I have guests, so no time for long emails. Here is the code (I have tested it, and it works): ============================================ open Thread open Graphics let code1 () = let x = ref 0 in while true do incr x; Printf.printf "alpha %d\n" !x; flush stdout done let code2 () = open_graph " 300x300"; while true do let st = wait_next_event [Key_pressed] in Printf.printf "key %c pressed...\n" st.key; flush stdout done let _ = ignore(Thread.create code1()); code2() ============================================ Ciao, Oliver