yyzybb537 / libgo

Go-style concurrency in C++11
MIT License
3.22k stars 758 forks source link

Scheduler DispatchThread的一个调度问题 #128

Closed magicsupery closed 5 years ago

magicsupery commented 5 years ago
        if (p->active_) {
            actives.insert(ActiveMap::value_type{loadaverage, i});
            p->Mark();
        }

        **1.这里为啥要有这个判断呢,如果p有runableSize的话,是不会处于wait状态吧?
        newQueue每次add都会调用OnaddTask,会去激活
       runableQueue空时才会去wait,是否存在一种时序是我没有想到的,需要在这里激活呢?**
        if (loadaverage > 0 && p->IsWaiting()) {
            p->NotifyCondition();
        }
    }
yyzybb537 commented 5 years ago

Thread Dispatch: OnAddTask -> IsWaiting = false -> the end. Thread Process: All run done -> setWaiting -> the end.

magicsupery commented 5 years ago

确实,忘记了OnAddTask的实现需要判断的,这样确实更好

yyzybb537 commented 5 years ago

为了更好的性能,这个wait和notify机制是不锁的,所以需要dispatchThread补救

magicsupery commented 5 years ago

赞~