Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: Oliver Bandel <oliver@f...>
Subject: Re: [Caml-list] Why 'Graphics.wait_next_event' doesn't reply anymore ?
Hi,


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

>   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