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: Fabrice Marchant <fabrice.marchant@o...>
Subject: Re: [Caml-list] Why 'Graphics.wait_next_event' doesn't reply anymore ?
  Hi Oliver !

 Thanks to have considered my problem.

On Sun, 11 Nov 2007 17:48:34 +0100
Oliver Bandel <oliver@first.in-berlin.de> wrote:

> http://caml.inria.fr/pub/ml-archives/caml-list/2002/09/d29ca3379fe68e3cdbd36323f5f409c0.en.html

> This code looks ugly.
...
> 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 think these 'yields' are only desperate attempts to hint the scheduler to do its job - that it doesn't as we could expected -.

> open Thread
> open Graphics
> 
> 
>   let code1 () =
>         let x = ref 0 in
>         while true do
>           incr x;
>           Printf.printf "alpha %d\n" !x;
>           flush stdout
(*                      ;
            display_mode false;
            fill_circle 100 100 20; 
            synchronize ()*)
>         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()
  Yes, it perfectly works.

So I compared it with my hanging example to try to understood what was responsible for blocking.

  If you uncomment the lines I inserted in code1, things begins to go more or less wrong.
On my computer, from time to time, when you alternatively focus console output and graphical window, some characters can be suddenly spat. Or keyboard input is completely ignored...

   Thanks to have make things progress ! I think we aren't far to understand.

Regards,

  Fabrice