Hello everyone, I have encountered a behaviour in my adventures with ChucK that I cannot really understand. Let's suppose the following classes: 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 ); } } class TTest { StereoTEnvelope envelope; fun void TFunction( int milliseconds ) { envelope.TFunction( milliseconds ); } } and then I do: ( TTest tTest ).TFunction( 5000 ); 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. ????? Dimitris ___________________________________________________________ Χρησιμοποιείτε Yahoo!; Βαρεθήκατε τα ενοχλητικά μηνύματα (spam); Το Yahoo! Mail διαθέτει την καλύτερη δυνατή προστασία κατά των ενοχλητικών μηνυμάτων http://login.yahoo.com/config/mail?.intl=gr
2009/8/15 Bozelos Dimitris
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 ); } }
class TTest { StereoTEnvelope envelope;
fun void TFunction( int milliseconds ) { envelope.TFunction( milliseconds ); } }
and then I do:
( TTest tTest ).TFunction( 5000 );
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.
?????
The parent shred dies, killing the child shred you sporked, before it can print its second message. Try: ( TTest tTest ).TFunction( 5000 ); me.yield(); -- Tom Lieber http://AllTom.com/
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 );
Thanks Tom and Hans, everything seems to work now! Dimitris ___________________________________________________________ Χρησιμοποιείτε Yahoo!; Βαρεθήκατε τα ενοχλητικά μηνύματα (spam); Το Yahoo! Mail διαθέτει την καλύτερη δυνατή προστασία κατά των ενοχλητικών μηνυμάτων http://login.yahoo.com/config/mail?.intl=gr
participants (3)
-
Bozelos Dimitris
-
Hans Aberg
-
Tom Lieber