-
Notifications
You must be signed in to change notification settings - Fork 72
Add coro::condition_variable #297
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
base: main
Are you sure you want to change the base?
Conversation
Hello @dobord , This is an awesome addition! Thank you for opening a PR. Can you please add a I also wonder if you could implement this without the |
Hello @jbaldwin! Regarding the dependency on |
Yeah excellent points, I was only considering the base |
Hello @dobord , I'm trying to add a If the timeout fires the notify task will need to be cancelled somehow, and vice versa (although the timeout task would eventually trigger...). |
Hello @jbaldwin, Super! Thanks a lot for the feature While writing tests for |
f286c47
to
d309cc1
Compare
db65306
to
d50ed2c
Compare
Hmm, this is a very strange linker error, I'm trying to figure out whats going on but it seems like gcc <= 13 is not including the when_any template functions in the output for some reason. |
Hello, @jbaldwin! |
Cool, I think that makes sense since the templates are now 'used' so they are not being optimized out. |
b287fc4
to
6f84a94
Compare
c24fa57
to
4387c6c
Compare
oops I didn't mean to update, meant to approve and run workflow... you'll have a conflict or need to force push if there are any more changes, my bad, giving it another review now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a quick look over the new coro::condition_variable
but I need some more time (ran out this morning but I will get to it!).
I really like the idea behind the default executor as well, its a nice addition.
Do you have a need to support emscripten for the example? It seems to complicate it a lot with the custom stop token, just curious.
include/coro/facade.hpp
Outdated
* Facade for universal access to default scheduler or default thread pool. | ||
* This facade supports the concept of coro::concepts::executor. | ||
*/ | ||
class facade |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think libuv calls this default_loop()
for a similar concept implementation, so this could be possibly named default_executor()
?
I think its interesting trying to abstract away which executor it is, but I wonder if it would be better to simply have:
- static coro::default::io_executor() -> coro::io_scheduler&
- static coro::default::executor() -> coro::thread_pool&
And the user can choose which one to use, I would think they should know if they are compiling with or without the networking support? It should also reduce a lot of the duplicate code from the facade.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps these should be returning std::shared_ptr<T>
since most functions/objects in the library takes those as arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remade default_executor, now it has 4 global functions in the namespace coro::default_executor.
9fea175
to
cb49cc7
Compare
Hello, @jbaldwin! It seems impossible to make In general, I would really like to spread the use of default_executor throughout the library to maximize performance improvements when resuming coroutines. There is another idea, of course it goes far beyond the scope of this PR#297, I would like to make another coro::scheduler based on coro::thread_pool, which would support the entire interface of coro::io_scheduler except for working with epoll (network, file descriptors, etc.). It would also be cool to make a concept for this scheduler. And after that implement in coro::default_executor the choice between coro::scheduler or coro::io_scheduler as the main scheduler for the application. |
8df6ed8
to
4b1c221
Compare
How would you feel about splitting out the facade/default_executor to another PR? It feels like its own feature. I might give a stab at the options that you talk about, but I'm also wondering if the defaults for them are good enough? Regarding the |
I think it's a great idea to split facade/default_executor into another PR. |
Regarding the |
coro::condition_variable is now an instance of the coro::condition_variable_base template, which accepts the strategy parameter
coro::condition_variable_base
performance with many waiters
completely lockfree
coro::mutex in wait_*()
strategy_based_on_io_scheduler::timeout_task
3c406ba
to
82cb974
Compare
ffb8d89
to
ed78dc8
Compare
ed78dc8
to
17006b1
Compare
Added coro::condition_variable to work together with coro::mutex for scenarios where std::mutex and std::condition_variable need to be replaced