alibaba / async_simple

Simple, light-weight and easy-to-use asynchronous components
Apache License 2.0
1.69k stars 251 forks source link

coro::ConditionVariable is not aware of Executor #361

Closed ChuanqiXu9 closed 9 months ago

ChuanqiXu9 commented 10 months ago

Now coro::ConditionVariable::notify*() will resume all the awaiting tasks in the notifying thread. It is not desired. The notifying thread may be blocked. Also this behavior violates the design principles of async_simple.

The expected behaviors may be that the coro::ConditionVariable::notify() should send all (or one) the waiting Lazy to the executor of the corresponding Lazy(s). Maybe it will be good to have notify*(Executor*) overloads to schedule the Lazy(s) not owned by executors by the specified Executors.

Note that this change may require CondtionVariable to be called in Lazy Coroutines, which may introduce a break change.

CC: @poor-circle

poor-circle commented 10 months ago

I will try to fix it later.

RainMark commented 9 months ago

ConditionVariable没实现coAwait的话,我记得会走ViaCoroutine回到之前suspend的线程,不会卡nofity线程吧

poor-circle commented 9 months ago

ConditionVariable没实现coAwait的话,我记得会走ViaCoroutine回到之前suspend的线程,不会卡nofity线程吧

是的,所以这个issue可以close了,只要发起wait的协程有绑定调度器,notify就会通过ViaCoroutine调度回去。如果没有绑定调度器则会原地执行。