From: Fabrice Marchant <fabrice.marchant@orange.fr>
To: caml-list@inria.fr
Subject: Why 'Graphics.wait_next_event' doesn't reply anymore ?
Date: Sat, 10 Nov 2007 23:01:45 +0100 [thread overview]
Message-ID: <20071110230145.3aebafe4@localhost.localdomain> (raw)
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
next reply other threads:[~2007-11-10 23:00 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-10 22:01 Fabrice Marchant [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20071110230145.3aebafe4@localhost.localdomain \
--to=fabrice.marchant@orange.fr \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox