@Jie, if the target processes in “.onAny(defer())” are the same, is it still 
un-ordered?

> On Mar 29, 2016, at 09:19, Qian Zhang <zhq527...@gmail.com> wrote:
> 
> So the point is, if the state of the future is set to READY between
> .onAny(callback_A) and .onAny(callback_B) and before callback_A is executed
> in this thread, another thread comes in and does onAny(callback_B), then
> callback_B will be executed immediately in this thread, and callback_A will
> only be executed when the previous thread comes in again, right?
> 
> 
> Thanks,
> Qian Zhang
> 
> On Tue, Mar 29, 2016 at 8:50 AM, Jie Yu <yujie....@gmail.com> wrote:
> 
>> Hi,
>> 
>> 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
>> 

Reply via email to