English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Why 'Graphics.wait_next_event' doesn't reply anymore ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-11-11 (16:48)
From: Oliver Bandel <oliver@f...>
Subject: Re: [Caml-list] Why 'Graphics.wait_next_event' doesn't reply anymore ?

Zitat von Fabrice Marchant <fabrice.marchant@orange.fr>:

>   Replying to myself :
>   Found this 2002 - unanswered ... thread - : "Graphics.wait_next_event ()
> blocks other threads"

This code looks ugly.


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

  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

let _ =
  ignore(Thread.create code1());