[chuck-users] dangerous games with shreds

lucas samaruga samarugalucas at gmail.com
Mon Nov 10 07:05:15 EST 2008


Hello

    I think it's a logic problem, ChucK can't worry about everything. Other
example, If you yiel two shereds in a particular way the time don't pass (I
can't code it right now).
    Maybe I'm wrong...

Cheers
Lucas

2008/11/9, eduard aylon <eduard.aylon at gmail.com>:
>
> Sorry list for bombing you with so many questions, but got this funny one,
> which I thought would be interesting to post. The patch below loops
> endlessly although no while(true) loop exists in the "main". If you try the
> patch, be warn that your computer may (or may not) become unresponsive. The
> code makes sense, and the behaviour as well, but should chuck throw a
> warning when something like this happens? I came up with this, while trying
> to have a process for reading and another for writing, but didn't want to
> advance time in any of them.
>
> eduard
>
> class mySpork
> {
>  Event write;
>  Event read;
>
>  fun void start(){ read.signal(); <<<"started">>>; }
>
>  fun void Write()
>  {
>    // NOTE: time is not advanced in this function
>    while(true)
>    {
>      write => now;
>      //<<< "writing" >>>;
>      read.signal();
>    }
>  }
>
>  fun void Read()
>  {
>    // NOTE: time is not advanced in this function
>    while(true)
>    {
>      read => now;
>      //<<< "reading" >>>;
>      write.signal();
>    }
>  }
> }
>
> mySpork myspork;
> spork~myspork.Read();
> spork~myspork.Write();
> me.yield();
> myspork.start();
> <<< "loops forever">>>;
> 1::second => now;
> <<< "and never gets here">>>;
>
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20081110/72373d30/attachment.htm>


More information about the chuck-users mailing list