Thanks for the explanation, Peter, and for accompanying me on this
journey into the unknown. Your description of enqueue is what chouser
explained to me too.

Someday I have to write some code with a queue named eat so that eat
will pop itself.

Cheers,
Michael


On May 26, 5:54 pm, Peter Schuller <peter.schul...@infidyne.com>
wrote:
> > Where is Action's execute method called in the event the queue is not
> > empty?
>
> If the agent's queue was non-empty from the perspective of enqueue(),
> that means one of the following is true:
>
> (1) A previous enqueue() has already scheduled the execution of an
> action, but it has not yet begun running.
> (2) doRun() is running but has not yet completed its CAS loop at the end.
>
> In either case, once doRun() runs and reaches its CAS loop, it will
> detect that the queue is non-empty and schedule the next action. This
> is the:
>
>                         if(error == null && next.q.count() > 0)
>                                 ((Action) next.q.peek()).execute();
>                         }
>
> which appears towards the end of doRun(). Next is the atomically
> obtained (through CAS looping) queue, after it popped itself.
>
> Another way to look at it might be that the queue can be in two
> relevant states at any point in time:
>
>   * empty
>   * non-empty
>
> In the non-empty state, doRun() is continuously responsible for
> re-scheduling itself. In the empty state, enqueue() is responsible for
> scheduling it. Because of the use of CAS loops, the transition from
> "empty" to "non-empty" can be atomically detected by enqueue(),
> allowing it to determine whether or not it was responsible for such a
> state transition, in which case it schedules the action for execution.
>
> --
> / Peter Schuller

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to