[chuck-users] implementing a "wait for signal with timeout"

dan trueman dtrueman at Princeton.EDU
Mon Jun 8 13:59:15 EDT 2009

jah, i've requested something like this before:

myEvent  ||  1::minute => now; //time advances to whichever comes  

i've programmed around it using secondary timing shreds, but it would  
be much nicer to be able to do something like the above...


On Jun 8, 2009, at 1:53 PM, Robert Poor wrote:

> Gang:
> In real-time music making, sometimes you want to wait for a signal  
> (e.g. event.broadcast()) OR for a specific time to elapse, whichever  
> comes first.  I've implemented ways to do this, but I'm not really  
> satisfied with the code.
> Here's the problem: Lets say that your music is slaved to a  
> metronome, and the metronome is allowed to change speed.  You want  
> your music to stay sync'd to the metronome.  If you simply do:
> 	now + (1/tempo)::second => time next_beat;
> 	next_beat => now;
> 	play_note();
> you'll be in trouble if the metronome speeds up while you're  
> waiting: your note will be late.  The fundamental problem is that  
> once you execute "next_beat => now;", you're committed to waiting  
> and there's now way to break out of it, short of killing the  
> thread.  The problem with killing the thread is that you leak 88K  
> with each thread (!!!).
> So here's the programming challenge: how would you implement a "wait  
> for signal with timeout" that will block until it gets a signal OR a  
> specified time has elapsed?  Since each thread costs 88K in non- 
> reclaimed memory, you may create threads, but your solution must re- 
> use them.
> As I said, I have implementations which I'm happy to share, but I'd  
> like to see how you would do this first.  Most of all, this is  
> likely to turn into a feature request for the next version of ChucK.
> - Rob
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users

More information about the chuck-users mailing list