[chuck-users] Return values of sporked functions?

Spencer Salazar ssalazar at CS.Princeton.EDU
Sat Jun 7 11:48:50 EDT 2008


On Jun 7, 2008, at 5:04 AM, Peter Todd wrote:

> Hi all,
> Couldn't find this one in the manual.  Where do sporked funcitons
> return to?  How do I get the return value of a spoked function?
> they don't and you won't, I fear..... (or shred-heaven, depending on  
> your persuasion)
> Shred-heaven would have been my assumption, but it doesn't appear to  
> be the case, and it does make a difference..... at the moment, it  
> appears that if you run
> // <chuck>
> int addThree(int i){
>     <<< "adding three..." >>>;
>     return i + 3;
> }
> <<< "about to spork..." >>>;
> spork ~ addThree(2);
> <<< "sporked" >>>;
> // </chuck>
> then you get neither an error, nor the message "adding three...";  
> but you do get the other two messages.  So, say the main purpose of  
> the function was to do a load of other stuff, and the return value  
> was just there for conveniance, or to return any error code perhaps  
> (and you didn't expect to be able to read it in the context of  
> sporking the function)... you get some rather unexpected behaviour,  
> it seems to me.

This behavior does make some sense.  When a shred exits, it kills any  
shreds it sporked.  Additionally, when a shred is sporked, it is not  
scheduled to run immediately, but rather added to a FIFO queue of  
shreds to run after the current shred yield()'s or x => now;'s.  The  
potentially thorny part is that, when a shred exits, the "exit"  
operation occurs before any shreds on the run queue are scheduled to  
execute. Thus, any recently sporked shreds are killed before running  
at all.

So, for what its worth, the behavior of all three messages printing  
can be achieved by adding a
at the end of the program above.  me.yield() effectively exhausts the  
run queue before returning.


> Regards,
> Peter
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users

More information about the chuck-users mailing list