[chuck-users] durations and control structures

Ge Wang gewang at CS.Princeton.EDU
Wed Apr 19 17:09:16 EDT 2006

> Hi there list,

Hi Tim!

> I'm new to this chuck business and am trying to get a handle on a
> number of things - timing and durations are one of them.  If I have a
> chunk of code that I'd like to run for a specific duration of time,
> how could I go about defining this in the control structure?
> something like
> while (duration condition here)
> {
> 	do this
> }

Depending on what you want to do, there are many ways to run a chunk of 
code for a specific duration of time.   One of the ways to use time in 
the loop conditional:

// some length of time
20::second => dur length;
// compute end time relative to now
now + length => time later;

// this should run the loop for duration 'length'
while( now < later )
     // do stuff, make sure to advance time somewhere

This is one way, and of course the specifics depend on your 
application.  You can also do this with multiple shreds, where one 
controls others.  Let us know if you have questions with that.

I hope this helps.


More information about the chuck-users mailing list