durations and control structures
Hi there list, 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 } I understand that I could use some kind of counter that (de/) increments each iteration and use this to control the loop with a < or > operation, but one thing I might like to do in performance is vary the (poll rate) => now, and it would be nice for my control structure timing to remain intact with such operations. I'm sure there's a simple answer, but it avoids me. Thanks, --Tim
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. Best, Ge!
Thanks Ge, that was simple enough! I suppose controlling shreds would involve and removing shreds around a central structure like this? Once I spork one shred, can I give it a name so that I can remove it with chuck code? Thanks again, --Tm On 19-Apr-06, at 5:09 PM, Ge Wang wrote:
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.
Best, Ge!
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
I suppose controlling shreds would involve and removing shreds around a central structure like this?
That's one possibility. Another is to share data (or events) from multiple shreds, and using those to synchronize things.
Once I spork one shred, can I give it a name so that I can remove it with chuck code?
You can get a Shred reference back, and then refer to it by id: // define function fun void foo() { while( true ) { <<< "hi" >>>; .2::second => now; } } // spork the function, remember the shred reference spork ~ foo() @=> Shred @ s; // wait for 2 seconds 2::second => now; // remove by id machine.remove( s.id() ); // wait a little more 2::second => now; Best, Ge!
participants (2)
-
Ge Wang
-
Timothy Sutton