殷成涛

Results 2 comments of 殷成涛

我再补充下场景描述,对于一个线性变化的状态机来说,如果中间某个状态流转足够快(比如直接 return),那么通过线程池异步 fire 对应的 event 可能与上一个 event 近乎同时进入 queuedEvents ![image](https://user-images.githubusercontent.com/10680386/191882827-73b42426-51ac-40b9-97d9-8a71cae70562.png) 如下图所示,两个线程,其中一个刚好执行到 processEvents 中 data.read.currentRawState() 位置(持有写锁,标记 status 为 busy,e1 进入 queuedEvents),另一个刚刚提交 e2 进入 queuedEvents 并进入 processEvents 方法,那么两个线程都从 processEvents 方法返回后,queuedEvents 中还会存留一个 e2,如果后续不再有新的...

之前的改法有问题,仍然存在丢消息的可能,现在将外层改为 for 循环,确保离开方法时,queuedEvents 会被清空