caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Why  'Graphics.wait_next_event' doesn't reply anymore ?
@ 2007-11-10 22:01 Fabrice Marchant
  2007-11-11 14:07 ` [Caml-list] " Fabrice Marchant
  0 siblings, 1 reply; 16+ messages in thread
From: Fabrice Marchant @ 2007-11-10 22:01 UTC (permalink / raw)
  To: caml-list

  Hi !

  This issue with 'Graphics.wait_next_event' seems only to happen in some cases with threads.
Please consider the code snippet below :
---------------------------------------------------
let id = ref None

let run () =
  while !id <> None do
    step ();  (* Changes drawing state *)
    plot () (* ;
    Thread.delay 0.01 *)
  done

let rec test () =
  print "Graphics.wait_next_event, next statement...\n"; (* A flushed printf *)
  let status = wait_next_event [ Key_pressed ] in
  print "Graphics.wait_next_event returned.\n";
  match status.key with
    'r' ->
      (match !id with
        None -> id := Some (Thread.create run ())
      | Some _ -> ());
      test ()
  | 's' ->
      id := None;
      test ()
  | _ ->
      ()
-----------------------------------------------
  First time you press 'r', a thread is created. ( There is no delay problem in changing thread 'id' after creation and process test '!id <> None' is soon true at first call. )
  So the thread does its animation job. Here is the full short - stuck - test code :
http://fabrice.marchant.free.fr/code/wait_next_event/
After the thread is launched, we can check the console to state that the "main" thread is waiting for a key press.

The issue arises now.
 You can hit any key : 'Graphics.wait_next_event' couldn't care less.

Please why ?

  Another thing I do not understand :
if you insert a delay inside the 'run' thread code loop ( please see uncommentable Thread.delay above ), the program does not stick anymore, 'Graphics.wait_next_event' normally listening to the keyboard.
( Nice, but my aim was to run this thread at full speed... )

Thanks,

Fabrice


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2007-11-14  0:33 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-10 22:01 Why 'Graphics.wait_next_event' doesn't reply anymore ? Fabrice Marchant
2007-11-11 14:07 ` [Caml-list] " Fabrice Marchant
2007-11-11 16:48   ` Oliver Bandel
2007-11-11 18:35     ` Julien Moutinho
2007-11-11 20:13       ` Fabrice Marchant
2007-11-12  0:33       ` Oliver Bandel
2007-11-11 19:40     ` Fabrice Marchant
2007-11-12  0:43       ` Oliver Bandel
2007-11-12 19:54         ` Fabrice Marchant
2007-11-12 21:18           ` Oliver Bandel
2007-11-13  7:45             ` Fabrice Marchant
2007-11-13 10:14               ` Oliver Bandel
2007-11-13 20:10                 ` Fabrice Marchant
2007-11-14  0:33                   ` Oliver Bandel
2007-11-12  0:46       ` Oliver Bandel
2007-11-12  6:18       ` Oliver Bandel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).