Timers

Discussion of Common Lisp

Timers

Postby Harnon » Sat Dec 27, 2008 7:41 am

K, so i would like a timer which interrupts the lisp code and runs a specified code every x seconds. I've tried win32 standard timers, they don't work because they schedule based on how busy the program (cpu) is, and multimedia timers just crash lispworks (haven't tried any other platforms).

So, i started thinking that what i needed was a c timer program which would run in another thread, and call the lisp function whenever. But then I started thinking of all the thread issues involved, whether the lisp code called by the timer would be thread safe, etc.

But then again, i thought that there are already gui programs out there that do something similar. Cells-gtk allows interrupts, so there must be some way to get around these thread safety issues, even in a non-multitasking lisp.

So I guess my question is, are callbacks thread-safe when the function is called in the middle of a running lisp program?? :?:

Edit: On an afterthought, I might know why gui programs work. Most of the program is event based, meaning the code is run only when a button is clicked, a menu clicked, etc. So, it would be thread safe because only one event is called at one time. If one event code takes an excessively long time to execute, then maybe it would be impossible for the user to click another button, etc. until that code is completed, just like the win32 timers. Any thoughts?
Harnon
 
Posts: 78
Joined: Wed Jul 30, 2008 9:59 am

Re: Timers

Postby Ramarren » Sat Dec 27, 2008 9:20 am

Lispworks documentation has a chapter about timers: http://www.lispworks.com/documentation/lw51/LWUG/html/lwuser-234.htm. I don't use Lispworks, but this might be what you want. In general I doubt that generating interrupts from FFI code is a good idea, but this obviously depends on the implementation.
Ramarren
 
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland

Re: Timers

Postby Harnon » Sat Dec 27, 2008 9:44 am

Thx for the quick reply :D
I was thinking about using lispworks for this, but i hate to create something that isn't portable across lisp implementations, though i suppose it really wouldn't matter in the end.
Does anyone else have ideals about using callbacks from c to implement timers?
Thx again :)
Harnon
 
Posts: 78
Joined: Wed Jul 30, 2008 9:59 am

Re: Timers

Postby makia » Sat Dec 27, 2008 9:59 am

makia
 
Posts: 25
Joined: Tue Jul 22, 2008 2:37 am

Re: Timers

Postby Harnon » Sat Dec 27, 2008 11:22 am

Thx! I looked at the trivial-timeout, but it only supports those implementations with support for threads and/or timer scheduling. :cry:

I also did a simple test with the gui callbacks, and it appears i was right. The whole program is event driven, there is no other lisp code running unless an event is called, so its not multithreading. Also, only one event (i.e. code) can be executed in an instance.

I suppose that i could try using an implementation with thread support. However, i would like to eventually be able to run my application by clicking an image on the desktop. I know that lispworks doesn't support this in their free version. Does anyone know about allegro or any other implementation which allows image creation and supports threads on windows?
Harnon
 
Posts: 78
Joined: Wed Jul 30, 2008 9:59 am

Re: Timers

Postby makia » Sat Dec 27, 2008 2:02 pm

you should look ABCL or ECL if your target is windows and you dont want to pay lispworks or alegro cl
makia
 
Posts: 25
Joined: Tue Jul 22, 2008 2:37 am

Re: Timers

Postby Harnon » Sat Dec 27, 2008 10:39 pm

Wow! Ecl looks like exactly what i need, if i can manage to compile it (scratches head).
Harnon
 
Posts: 78
Joined: Wed Jul 30, 2008 9:59 am

Re: Timers

Postby nuntius » Mon Dec 29, 2008 6:39 pm

If you choose to go with ECL, I recommend MinGW over Cygwin; cygwin starts feeling like a sandbox/jail after a while. YMMV.

Also checkout Corman on MSWin. IIRC, the implementation is free; only the editor costs money (but its still fairly cheap).
User avatar
nuntius
 
Posts: 498
Joined: Sat Aug 09, 2008 10:44 am
Location: Burlington, MA


Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 8 guests

cron