[PD-dev] interrupting a method

Frank Barknecht fbar at footils.org
Sun May 14 10:40:58 CEST 2006


Hallo,
Julian Villegas hat gesagt: // Julian Villegas wrote:

> I receive a list by one inlet and perform some computation with the data until a new list arrives or the execution reach a time limit defined by the user as a parameter of the object. 
> The method should put whatever value it got to one outlet if it reach the deadline, and wait for new data to arrive. If data arrives before the deadline, the method should abort the ongoing computation and start doing it again with the new data.
> I tried this simple example to see if the mechanism will work:
> 
> void foo(t_interrupt *x){
>     int i=0;
>     double timenow = clock_getlogicaltime(); 
>     post("timenow =  %f",timenow);
>     while(i<=10000)
>     {
>         i++;
>         post("now  =  %f",clock_gettimesince(timenow));        
>     }
> }
> 
> but I only get 0.0000 as outputs... 

Thank god you get zero: Logically no time passed between the call to
the "foo" function and the time, when it is finished with counting to
10000 or to 1000000000000000000000000000. 

That's how most objects in Pd work: It doesn't matter, how long
something like the [cos] object takes on a specific machine to
calculate the cosine, the result is assumed to be there immediatly.
If it should not be there immediately you need a clock, see below.

You could use "sys_getrealtime" to get the real time a calculation
took, however if you want to delay the time your object takes for
outputting its computation's results you need something like [metro]
or [del] do. You may look a its source in x_time.c, where you see that
metro has a "metro_tick" method and also its own clock, created with
"clock_new" and delayed with "clock_delay". 

> Furthermore, I'm not sure if it will work. Should I make a class
> that implements the calculation in its own thread? or Pd's
> scheduling methods will do the job?... 

This depends on what exactly you want to do. You can delay actions
using the Pd clock, however I think, if you want an ongoing
calculation you may indeed need a thread. But I don't know that area
in Pd very well, so you and I should better wait for others to answer
this.

Ciao
-- 
 Frank Barknecht                 _ ______footils.org_ __goto10.org__




More information about the Pd-dev mailing list