You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@mesos.apache.org by "haosdent (JIRA)" <ji...@apache.org> on 2016/04/01 19:48:25 UTC

[jira] [Created] (MESOS-5079) Ordering guarantee of future.onAny callbacks

haosdent created MESOS-5079:
-------------------------------

             Summary: Ordering guarantee of future.onAny callbacks
                 Key: MESOS-5079
                 URL: https://issues.apache.org/jira/browse/MESOS-5079
             Project: Mesos
          Issue Type: Bug
            Reporter: haosdent


Just copy the discussion from dev mailing list [Ordering guarantee of future.onAny callbacks | http://search-hadoop.com/m/0Vlr6hEZyWYHiwg2]

{noformat}
...
While digging a bug reported in, I realized an assumption we shouldn't make
in our code.
https://issues.apache.org/jira/browse/MESOS-5023

Say you have the following code:

void some_func()
{
  future
    .onAny(callback_A)
    .onAny(callback_B);
}

Question: will callback_A already be executed before callback_B?

The answer is NO. We should never assume that. Under the following
interleaving, callback_B can be invoked first:

Thread-1                                       Thread-2

onAny(callback_A) {
  onAnyCallbacks.push_back(callback_A);
}
                                                      set() {
                                                        lock()
                                                        if (state ==
PENDING) {
                                                          state = READY;
                                                          result = true;
                                                        }
                                                        unlock();

onAny(callback_B) {
  lock()
  if (state != PENDING) {
    run = true
  }
  unlock()

  if (run) {
    callback_B()
  }

                                                         if (result) {

internal::run(data->onAnyCallbacks,
*this);
                                                         }

- Jie
{noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)