I am working on a complete rewrite of my Masking package (the original was too bulky and dependant on creating hundreds of shreds), and was wondering just how something is scheduled in ChucK. Basically, I am trying to create a single shred that handles the updating of various parameters (as opposed to the original which had a shred for each parameter), and in doing so, I would like to create a "locking" mechanism around an array used to control which parameters get updated, and when. On one shred, there is the code that controlls the updating of parameters, this shred runs for the life of the program (or some portion of). On the second shred (most likely the main shred), the array containing the references to the parameters to be updated needs to be locked to prevent having a new reference added while the first shred is actually updating the parameters. (Does this make sense?) So, what I would like to know is how the following code would execute. now + 0::ms => now; Would this push the execution of the code to follow to the end of the current time slice? Or is this functionality undefined, and would it execute these shreds in an arbitrary fashion? In a nut shell, this is the code from the updating shred that locks the array... (this is embedded in an object) false => int locked; false => int keepGoing; MController @ controllers[]; // this gets initialized to match the number of controlled parameters fun void helper(....) { true => keepGoing; while(keepGoing) { while(locked) { now + 0::ms => now; } true => locked; for(0 => int i; i < controllers.cap(); i++) { if (controllers[i] != null) { <<< "do something with this controller", "" >>>; } } false => locked; } } The variable 'locked' controlls the access to the 'for' loop, and the variable 'keepGoing' controlls the outer loop. 'keepGoing' is set to true at the top of this code, but will be set to false by another shred to force the 'helper' function to exit as needed. The array 'controllers' is accessed by both this shred, as well as the main shred to add -- Help the Environment, Plant a Bush back in Texas!
participants (1)
-
Mike McGonagle