I seem to understand it.  `nested' is seen non-null value in the thread
_that executes the action_.  In any other threads, the default null value
will be seen.  And in the executing thread, after pending sends are
released, no user code will be executed, so no actions will be dropped.

Best Regards,
Guanpeng Xu

On Tue, Mar 27, 2012 at 3:07 PM, Guanpeng Xu <herberteu...@gmail.com> wrote:

> Howdy group, I was reading the implementation of Agent -- Agent.java,
> and have a question on nested send/send-off's.
>
> When an action is being executed, send/send-off's are queued in the
> persistent vector `nested':
>
> static void dispatchAction(Action action){
>        LockingTransaction trans = LockingTransaction.getRunning();
>        if(trans != null)
>                trans.enqueue(action);
>        else if(nested.get() != null)
>                {
>                nested.set(nested.get().cons(action));
>                }
>        else
>                action.agent.enqueue(action);
> }
>
> They're only added to that vector when nested.get() isn't null.
> nested becomes non-null when executing an action:
>
>        static void doRun(Action action){
>                try
>                        {
>                        nested.set(PersistentVector.EMPTY);
>
>                        Throwable error = null;
>                        try
>                                {
>                                Object oldval = action.agent.state;
>                                Object newval =
>  action.fn.applyTo(RT.cons(action.agent.state,
> action.args));
>                                action.agent.setState(newval);
>                                // ... ...
>
> If there's no error in the execution, pending sends will be added back
> into the agent's own queue:
>
> // method Action.doRun()
>                        if(error == null)
>                                {
>                                releasePendingSends();
>                                }
>
> and nested will be reset to null with a `finally' clause:
>
> // method Action.doRun()
>                finally
>                        {
>                        nested.set(null);
>                        }
>
> I think there is a fatal problem here, correct me if I'm wrong.  If
> some pending actions are sent _after_ releasePendingSends() returns
> but _before_ the the `finally' clause getting executed, aren't they
> dropped?
>
> Best Regards,
> Guanpeng Xu

-- 
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