[chuck-users] spork question
Hans Aberg
haberg at math.su.se
Sat Aug 15 17:13:46 EDT 2009
On 15 Aug 2009, at 22:25, Bozelos Dimitris wrote:
> I have encountered a behaviour in my adventures with ChucK that I
> cannot really understand. Let's suppose the following classes:
...
> The function in StereoTEnvelope that I call with envelope.TFunction
> proceeds as expected printing 'now' both before and after advancing
> time. But the function that I spork prints only before and then quits.
Probably as soon as the main shred finishes, the program terminates,
so all other shreds are killed off. This is the normal behavior for
POSIX threads, anyway. So one must have the main thread/shred to wait
for the others to finish. Since Chuck has perfect timing, it will
suffice to add some time to the main shred. Like the code below.
Hans
class TEnvelope
{
fun void TFunction( int milliseconds )
{
<<< "before", now >>>;
milliseconds::ms => now;
<<< "after", now >>>;
}
}
class StereoTEnvelope
{
TEnvelope envelopeL;
TEnvelope envelopeR;
fun void TFunction( int milliseconds )
{
spork ~ envelopeL.TFunction( milliseconds );
envelopeR.TFunction( milliseconds + 1 );
}
}
class TTest
{
StereoTEnvelope envelope;
fun void TFunction( int milliseconds )
{
envelope.TFunction( milliseconds );
}
}
( TTest tTest ).TFunction( 5000 );
More information about the chuck-users
mailing list