[chuck-users] can there be many ::ms in while?

mike clemow gelfmuse at gmail.com
Fri Aug 3 11:29:38 EDT 2007


All,

That was very well explained, folks.  Personally, I think that the
area of the manual describing concurrency in Chuck is a little bit
thin.  It would really help people new to Chuck (like myself) to have
a series of examples of what can be done with the concurrency
features, syncing, & c.  It's one of Chuck's most important and
powerful features.

Maybe we could add a little section of the Wiki for concurrency
examples?  Chuck/Programs/Concurrency or something like that.

I wish I had some examples of sporked shreds sharing data with each
other, for instance.

Just thinking out loud...
Mike



On 8/3/07, Martin Ahnelöv <operagasten at gmail.com> wrote:
>
> >
> > That's also quite simple. You can run threads (we call them shreds)
> > next to the main one. You define those as functions and you "spork"
> > the function.
> > =======================================
> > //let's define a function
> > fun void paralel()
> > {
> > while(true)
> >     {
> >     //this will loop forever
> >     <<<"beep">>>;
> >     second => now;
> >     }
> > }
> >
> >
> > //let's try sporking it
> > spork ~ paralel();
> >
> > //now we write the main loop that will run next to it
> > while(true)
> > {
> > //this will also loop forever
> > <<<"boop">>>;
> > .75::second => now;
> > }
> >
> >
> > //anything that you would write here will never get executed because
> > the program will always be stuck in that last loop. you could still
> > define functions here though.
> >
> > -----------------------------
> >
> > See? not at all hard. You can run as many functions next to eachother
> > as you like, they can all be different or they could all be the same.
> > If they are all the same you only need to define it once and can spork
> > it as many times as you'd like (untill the cpu gives up! Notice that
> > they can all run at different speeds if you'd like, in my example
> > above one loops in .75 seconds while the other takes a whole second so
> > they will drift in and out of phase.
> >
>
> Cool! Thanks!
>
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>


-- 
http://shadowofaculture.blogspot.com


More information about the chuck-users mailing list