Skip to content

Comments

fix signal dont triggered bug in collectAll & slot::emplace()#414

Merged
ChuanqiXu9 merged 1 commit intoalibaba:mainfrom
poor-circle:main
Jan 23, 2025
Merged

fix signal dont triggered bug in collectAll & slot::emplace()#414
ChuanqiXu9 merged 1 commit intoalibaba:mainfrom
poor-circle:main

Conversation

@poor-circle
Copy link
Collaborator

@poor-circle poor-circle commented Jan 23, 2025

Why

slot::emplace()

When we call slot::emplace(), we check signal state before construct handler. however, when signal::emit() called, it will set signal state then set the construct handler.

A possible order:

  1. Thread A: slot::emplace() check signal state, no triggered now.
  2. Thread A: slot::emplace() construct signal handler.
  3. Thread B: signal::emit() set signal state
  4. Thread B: signal::emit() load signal handler and found it's nullptr, emit over
  5. Thread A slot::emplace() set the signal handler by CAS successful. return true.

Now, slot::emplace() will return true and signal handler won't be executed. the signal is loss.

collectAny

collectAny should emit signal when the first handler resume, but now it may won't emit it if downCount was called in await_suspend

What is changing

slot::emplace()

slot::emplace() will construct signal handler before check signal state.

Because signal::emit() will always set state before load signal handler. so if signal::emit() load signal handler result is nullptr, slot::emplace() will always get the signal by check state.

collectAll and collectAny

Remove downCount call in await_suspend

Example

@poor-circle poor-circle changed the title fix signal dont triggered bug in collectAll & emplace fix signal dont triggered bug in collectAll & slot::emplace() Jan 23, 2025
@poor-circle
Copy link
Collaborator Author

@ChuanqiXu9 All ci passed

}
func();
}
_event.setAwaitingCoro(continuation);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the coroutine may be suspended forever if the input was empty.

Copy link
Collaborator

@ChuanqiXu9 ChuanqiXu9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variadic version has a static_assert for the inputs size.

@ChuanqiXu9 ChuanqiXu9 merged commit 18f3882 into alibaba:main Jan 23, 2025
14 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.

2 participants