Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

event 处理并发安全咨询 #137

Open
yinwoods opened this issue Sep 22, 2022 · 1 comment
Open

event 处理并发安全咨询 #137

yinwoods opened this issue Sep 22, 2022 · 1 comment

Comments

@yinwoods
Copy link

image

请教下,目前 event 处理的并发安全依赖 queuedEvents + isIdle 状态判断,如果某个时刻进入截图中框住的部分,另一个线程提交了一个 event 进入 queuedEvents,这个 event 是不是就不会被处理了

@yinwoods
Copy link
Author

yinwoods commented Sep 23, 2022

我再补充下场景描述,对于一个线性变化的状态机来说,如果中间某个状态流转足够快(比如直接 return),那么通过线程池异步 fire 对应的 event 可能与上一个 event 近乎同时进入 queuedEvents
image

如下图所示,两个线程,其中一个刚好执行到 processEvents 中 data.read.currentRawState() 位置(持有写锁,标记 status 为 busy,e1 进入 queuedEvents),另一个刚刚提交 e2 进入 queuedEvents 并进入 processEvents 方法,那么两个线程都从 processEvents 方法返回后,queuedEvents 中还会存留一个 e2,如果后续不再有新的 event 进入队列,触发 processEvents(),则这个 e2 就不再会被处理,造成状态机状态流转卡住的现象
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant