Allegro 8.0 Infinite Loop Stalling
Posted: Sun Feb 01, 2009 7:06 am
I'm trying to create a mouse polling loop in a thread. For an easy example of my problem, consider this code:
This will produce a very noticeable stall in allegro lisp (as in it almost freezes).
However, if I comment in the (print "HI" #.*standard-output*) the thread appears to not slow down Allegro in any manner and, most importantly of all, every time i push the mouse button it correctly outputs the "button press" event. Same for scroll.
I tried adding a (sleep .01) in the loop, but it is still freezing. Notice that you have to add
in order to get down to sleeps of .01 seconds.
(sleep .1) seems to be to long of a time and doesn't work because each event, I think, is being overwritten by another event which has occurred.
So I'm at a loss of how to imitate the anti-freezing affect of print, because i don't actually want something printed out on the screen. I guessed that what print does was slow down the loop so it wouldn't stall, but sleep, which I thought would do the same thing, doesn't work for less than .1 seconds because it starts stalling allegro lisp.
Notice that the same effect can be replicated by running
EDIT: Sorry, I'm using Allegro 8.1 under Windows XP. Oh, and actually when i use .1 seconds it will sporadically print button press events and will eventually print a whole slew of them, inferring that the c library i'm using does store events. (I'm using manymouse)
Code: Select all
(portable-threads::spawn-thread
"MOUSE"
(lambda ()
(loop
; (print "HI" #.*standard-output*)
(handler-case
(poll-mouse
nil
(:button (print "button press" #.*standard-output*))
(:scroll (print "scroll" #.*standard-output*)))
(error () ))
)))
However, if I comment in the (print "HI" #.*standard-output*) the thread appears to not slow down Allegro in any manner and, most importantly of all, every time i push the mouse button it correctly outputs the "button press" event. Same for scroll.
I tried adding a (sleep .01) in the loop, but it is still freezing. Notice that you have to add
Code: Select all
(setf (sys::thread-control :clock-event-delta) 10)
(sleep .1) seems to be to long of a time and doesn't work because each event, I think, is being overwritten by another event which has occurred.
So I'm at a loss of how to imitate the anti-freezing affect of print, because i don't actually want something printed out on the screen. I guessed that what print does was slow down the loop so it wouldn't stall, but sleep, which I thought would do the same thing, doesn't work for less than .1 seconds because it starts stalling allegro lisp.
Notice that the same effect can be replicated by running
Code: Select all
(portable-threads::spawn-thread
"test"
(lambda ()
(loop
;(print "HI" #.*standard-output*) makes the loop here not stall
(+ 2 3))))
EDIT: Sorry, I'm using Allegro 8.1 under Windows XP. Oh, and actually when i use .1 seconds it will sporadically print button press events and will eventually print a whole slew of them, inferring that the c library i'm using does store events. (I'm using manymouse)