Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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 ?

Zitat von Fabrice Marchant <>:

>   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());