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

fix potential issue of statemachine trigger lost #69

Merged
merged 1 commit into from
Sep 1, 2023

Conversation

liang-kang
Copy link
Contributor

there exists a tiny gap between finishing iterations of firing queued event and sm.op decrease

If another routine run internalFireQueued in that gap, it will not firing but save trigger in eventqueue and return.

Meanwhile, origin routine will not check event queue again because interations has finished

so such trigger event will be left in queue and wait for later firing trigger to executing.
If no trigger again, this trigger event will wait for ever and break run-to-complete

BTW, it's better not to execute all event in one loop,
which may cause Fire() caller waits for a long time to execute some actions not belong to current trigger.
So, in each loop, try to compare and swap sm.ops from 0 to 1, if failed, let current routine has chance to return.

there exists a tiny gap between finishing iterations of firing queued event and sm.op decrease
If another routine run internalFireQueued in that gap,
it will not firing but save trigger in eventqueue and return
Meanwhile, origin routine will not check event queue again because interations has finished

so such trigger event will be left in queue and wait for later firing trigger to executing.
if no trigger again, this trigger event will wait for ever.
@qmuntal
Copy link
Owner

qmuntal commented Sep 1, 2023

Thanks @liang-kang. I like the proposed changes. Merging.

@qmuntal qmuntal merged commit a570685 into qmuntal:asyncqueued Sep 1, 2023
10 checks passed
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

Successfully merging this pull request may close these issues.

None yet

2 participants