From: anusha
Subject: timer in lisp
Date: 
Message-ID: <0a1779938c1275666fdbfe03dccec3c6@localhost.talkaboutprogramming.com>
Hello everybody.
Is there a possibility of using a timer in LISP?
i.e. when a task starts the timer should start. After some particular
predefined time the task should stop running. Is there any such provision
in LISP?

Thanks,
Anusha.

From: Fred Gilham
Subject: Re: timer in lisp
Date: 
Message-ID: <u7mzunyr0l.fsf@snapdragon.csl.sri.com>
"anusha" <················@nospam.yahoo.co.in> writes:

> Hello everybody.
> Is there a possibility of using a timer in LISP?
> i.e. when a task starts the timer should start. After some particular
> predefined time the task should stop running. Is there any such provision
> in LISP?

Your terminology is a bit ambiguous.  By "task" do you mean what is
commonly called "thread"?  In Lisp "threads" are called "processes".

As people have already pointed out, this is implementation dependant.
But in the X86 implementations of CMUCL (which have multiprocessing)
you can use Unix timer facilities.  You can set a timer interrupt and
have your handler set a flag and your process check the flag to know
when to stop.

-- 
Fred Gilham                                 ······@csl.sri.com
[My tutors] got bored sooner than I, and laid down a general rule
that all statements about languages had to be in a higher level
language.  I thereupon asked in what level of language that rule was
formulated.  I got a very bad report.    -- J. R. Lucas
From: Raymond Toy
Subject: Re: timer in lisp
Date: 
Message-ID: <sxd651a6fic.fsf@rtp.ericsson.se>
>>>>> "Fred" == Fred Gilham <······@snapdragon.csl.sri.com> writes:

    Fred> Your terminology is a bit ambiguous.  By "task" do you mean what is
    Fred> commonly called "thread"?  In Lisp "threads" are called "processes".

    Fred> As people have already pointed out, this is implementation dependant.
    Fred> But in the X86 implementations of CMUCL (which have multiprocessing)
    Fred> you can use Unix timer facilities.  You can set a timer interrupt and
    Fred> have your handler set a flag and your process check the flag to know
    Fred> when to stop.

As I understand it, CMUCL is not interrupt-safe so these periodic
interrupts can cause weird things to happen.  A single interrupt is
probably ok, though.

Ray
From: Rob Warnock
Subject: Re: timer in lisp
Date: 
Message-ID: <QcmdnTtflfFxn5_fRVn-iw@speakeasy.net>
Raymond Toy  <···········@ericsson.com> wrote:
+---------------
|Fred Gilham <······@snapdragon.csl.sri.com> writes:
| Fred> But in the X86 implementations of CMUCL (which have multiprocessing)
| Fred> you can use Unix timer facilities.  You can set a timer interrupt and
| Fred> have your handler set a flag and your process check the flag to know
| Fred> when to stop.
| 
| As I understand it, CMUCL is not interrupt-safe so these periodic
| interrupts can cause weird things to happen.  A single interrupt is
| probably ok, though.
+---------------

And if all you do in it is set or clear an "MP:"-provided software mutex
[so some other thread will run the next time the "MP:" libarary is entered],
then it's probably o.k...


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Rob Warnock
Subject: Re: timer in lisp
Date: 
Message-ID: <QcmdnThflfHRn5_fRVn-iw@speakeasy.net>
Fred Gilham  <······@snapdragon.csl.sri.com> wrote:
+---------------
| But in the X86 implementations of CMUCL (which have multiprocessing)
+---------------

Well, they *call* is "multiprocessing", but it's actually just
multiprogramming, a.k.a. "green threads", all inside a single
Unix process. [Still, quite useful, since it's semi-transparently
integrated with non-blocking I/O...]


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Frank Buss
Subject: Re: timer in lisp
Date: 
Message-ID: <ctq4s9$p7l$1@newsreader2.netcologne.de>
"anusha" <················@nospam.yahoo.co.in> wrote:

> Hello everybody.
> Is there a possibility of using a timer in LISP?
> i.e. when a task starts the timer should start. After some particular
> predefined time the task should stop running. Is there any such provision
> in LISP?

you mean multithreading? Not in the Common Lisp standard, but most 
implementation have implemented it. In Common Lisp you can only call 
#'sleep, or you must implement a Lisp interpreter in Lisp, which can use 
#'get-universal-time to implement scheduling.

-- 
Frank Bu�, ··@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
From: Edi Weitz
Subject: Re: timer in lisp
Date: 
Message-ID: <uwttrxr63.fsf@agharta.de>
On Wed, 02 Feb 2005 03:51:46 -0500, "anusha" <················@nospam.yahoo.co.in> wrote:

> Is there a possibility of using a timer in LISP?  i.e. when a task
> starts the timer should start. After some particular predefined time
> the task should stop running. Is there any such provision in LISP?

That's implementation-dependent because multi-threading is not defined
in the ANSI standard.  You might want to look at the sources of the
ACL-COMPAT library which defines, besides other things, a WITH-TIMEOUT
macro that can be used with several popular CL implementations.

  <http://www.cliki.net/ACL-COMPAT>

Edi.

-- 

Lisp is not dead, it just smells funny.

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: Peder O. Klingenberg
Subject: Re: timer in lisp
Date: 
Message-ID: <ksbrb3qp37.fsf@beto.netfonds.no>
"anusha" <················@nospam.yahoo.co.in> writes:

> Is there a possibility of using a timer in LISP?
> i.e. when a task starts the timer should start. After some particular
> predefined time the task should stop running. Is there any such provision
> in LISP?

What others have said about multiprocessing is true, and investigating
what your implementations offers in terms of MP is probably
worthwhile.

However, if you are willing/able to break open the black box
abstraction of a "task", you could have it check time each run through
the loop and break out if it's over its limit.  Something like

(defun run-task ()
  (let ((start-time (get-universal-time)))
    (loop
     (do-single-task-step)
     (when (> (- (get-universal-time) start-time)
	      *arbitrary-time-limit*)
       (return-from run-task 'timeout)))))

This assumes that your "task" follows the pattern of a main loop
repeated many times and that the work in each iteration (the
do-single-task-step function above) is completed in a reasonably short
time compared to the time limit.  It also assumes that you have fairly
extensive influence on the tasks you will run.

These assumptions may or may not correspond to your reality, of
course, you don't really provide enough clues to tell.  But the above
should be competely within ANSI CL, and may be interpreted as a
"timer" if you squint. :)

...Peder...
-- 
I wish a new life awaited _me_ in some off-world colony.