[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] SystemClock-schedAbs explodes when time arg not used?



 wow, this is definitely interesting and IMO
non-trivial to find out, thanks James. This definitely
should be a candidate for insertion in a
quirks-and-mirks-in-SC3 help file


 --- James Harkins <jamshark70@xxxxxxxxx> escribió:

> On 9/22/05, Charlls Quarra
> <charlls_quarra@xxxxxxxxxxxx> wrote:
> 
> > 3
> > what is going on?
> > 0                   <---- 0? SHOULDNT IT BE 3??
> 
> Why would it be 3? 3.do will successively pass 0, 1,
> 2 to the i argument.
> 
> 3 will never enter the loop.
> 
> > Ok, everything fine (except that strange first 0
> > instead of 3) but now comment the line:
> > ("current time is "++time).postln;
> >
> > the sclang hangs and it get stuck dumping the
> value
> > i=0 value. This is a month or so old CVS. Should i
> > update or this happens also with current cvs?
> 
> When you schedule anything on a clock, the item is
> rescheduled for x
> beats later, where x is the return value of the item
> (the .yield value
> for a routine, or the return value of a function).
> That's if x is a
> SimpleNumber. If it's a non-numeric class, the item
> is not rescheduled
> and the thread comes to an end.
> 
> When you have the
> 
> ("current time is "++time).postln;
> 
> line in the function, the return value is a string,
> so the function is
> not rescheduled. When you remove it, the return
> value is i (which will
> be 0, 1 or 2).
> 
> When i == 0, a function will be rescheduled for
> immediate execution,
> so that thread takes over the virtual machine and
> doesn't let anything
> else execute. CRASH
> 
> The bottom line is, when you're scheduling a
> function, if there is
> even the slightest chance that the function will
> return the number,
> you should place some other value (such as nil) as
> the last thing in
> the function unless you want it to be rescheduled.
> Then it's the
> user's responsibility to make sure the return values
> are sensible for
> scheduling (e.g., not 0).
> 
> Not a bug, just a programming error (one which I've
> made more times
> than I care to admit).
> 
> For fun, try this:
> 
> (
> ~f = {|val| val.postln; };
> 
> 3.do{arg i;
>         SystemClock.schedAbs( thisThread.seconds +
> 5.0 , {arg time;
>           "what is going on?".postln; ~f.value( i+1
> );
> //                  ("current time is
> "++time).postln;
>             } );
> }
> )
> 
> Then you'll see the threads run repeatedly.
> 
> hjh
> 
> --
> James Harkins /// dewdrop world
> jamshark70@xxxxxxxxxxxxxxxxx
> http://www.dewdrop-world.net
> 
> "Come said the Muse,
> Sing me a song no poet has yet chanted,
> Sing me the universal."  -- Whitman
> 
> _______________________________________________
> sc-users mailing list
> sc-users@xxxxxxxxxxxxxxx
> http://www.create.ucsb.edu/mailman/listinfo/sc-users
> 



	


	
		
___________________________________________________________ 
1GB gratis, Antivirus y Antispam 
Correo Yahoo!, el mejor correo web del mundo 
http://correo.yahoo.com.ar