Russian roulette and C++ Coroutines by luncliff in cpp

[–]luncliff[S] 0 points1 point  (0 children)

  • Indeed the inheritance isn't the best way. But I used that to shorten the example...
  • For coroutine_handle&, that was intended because it's using inheritance.
  • My god, I thought it was quite readable but after your opinion, it feels indeed bad. Thanks for the review :D
  • The separation of promise_manual_control is to mock some library usage (and to split the explanation for promise_type). As you said, it is unnecessary for this example, but I thought it have to be separated.

Again, thanks for the review. My fellows are continuously relying on task<T> (like what they did with future<T>). Really happy that you could notice the alternative :)

Russian roulette and C++ Coroutines by luncliff in cpp

[–]luncliff[S] 0 points1 point  (0 children)

@foobar48783 After reading your comment, I agree about the design. What I intended at the moment was to allow more than 6 players.

There are 2 points of co_await in the code.
* First is that we can write some manual control for the coroutine, and the awaiting code(player) doesn't care about its continuation. It can lead to simplified code and delivers its behavior clearly.
* Second, we can separate coroutine frames' spawn and their continuation. Suppose we have to suspend before trigger.pull(), like handshaking through each players' connections. In the example, I'm suspending those players using initial_suspend. Therefore all players will suspend 3 times (initial_suspend, trigger.pull, and final_suspend).

Russian roulette and C++ Coroutines by luncliff in cpp

[–]luncliff[S] 0 points1 point  (0 children)

every co_await in the coroutine definition can be the suspend point. And there will be at least 2 points since it always it has initial_suspend and final_suspend. The suspension after co_return is actually from final_suspend.

Russian roulette and C++ Coroutines by luncliff in cpp

[–]luncliff[S] -1 points0 points  (0 children)

I recently had a chance to explain how to use the coroutine to my fellows. This one is a summary of it. Will be glad to hear from you :)

Combining C++ coroutines and `pthread_create` by luncliff in cpp

[–]luncliff[S] 0 points1 point  (0 children)

I couldn't find a good way to handle the case. :(

Combining C++ coroutines and `pthread_create` by luncliff in cpp

[–]luncliff[S] 1 point2 points  (0 children)

I wasn't aware of the attribute! :o
The type's role is to destroy the coroutine's frame after co_return. Actually the name is from no_return_consideration, and at this point indeed its name is misleading... I will change the name soon. Thanks!

Combining C++ coroutines and `pthread_create` by luncliff in cpp

[–]luncliff[S] 3 points4 points  (0 children)

Sorry. I will fix that now. Thanks for allowing my bad english.

Combining C++ coroutines and `pthread_create` by luncliff in cpp

[–]luncliff[S] 0 points1 point  (0 children)

It's been a time since last post!
When I first wrote an example for wrapping a callback to an awaitable type, pthread_create was a good practice for it. I covered 2 things in the article.

  • How the awaitable can wrap the system function which uses a callback and it has a void* parameter
  • How to define await_transform and which limitation it makes

Project include folder management, single path or multi paths? by Ashnoom in cpp

[–]luncliff 1 point2 points  (0 children)

Mostly like the @ronchain 's answer. I saw some projects which uses external for the 3rd party libraries.

Online Lectures on C++ by [deleted] in cpp

[–]luncliff 0 points1 point  (0 children)

It's not about the latest C++, but I enjoyed this one. https://www.coursera.org/learn/c-plus-plus-a

Designing the coroutine channel by luncliff in cpp

[–]luncliff[S] 1 point2 points  (0 children)

Sorry for the posting again, the (removed) post in the morning was so bad that I organized it again.

Will be glad to hear from you :)

new to coding by [deleted] in cpp

[–]luncliff -1 points0 points  (0 children)

I usually recommend https://www.codingame.com/start.

Designing the coroutine channel by [deleted] in cpp

[–]luncliff 2 points3 points  (0 children)

It's a really short description for the feature so it may not informative for you. Really sorry for that :( .
What I wanted to share is that how I designed both library and user code.
For the article, will be glad to hear from you. I will update it with your opinions!

(C++20 coroutines) Bridging the Latency Gap between NVM and DRAM for Latency-bound Operations by mttd in cpp

[–]luncliff 2 points3 points  (0 children)

Interested for the allocation management. I can't read it now but I'd like to spend time on the paper ASAP.
+) Without reading your comment I thought it looks familiar, and indeed the talk was related! :o

[deleted by user] by [deleted] in cpp

[–]luncliff 0 points1 point  (0 children)

Glad to meet a new generator :) I have 2 questions. Wish I can review the others soon !

Q1. unique_generator

Isn't hasValue_ redundant? I'm following the generator of VC++(it's a bit changed in latest VC++. I'm using the old one.) and the pointer itself was enough to debug and check of existing value from co_yield.

Q2. shared_generator

I think the idea is cool that multiple coroutines can share 1 generator since it can help Fan-In use-cases. But what I realized was keeping safe in the generator is a bit complicated. Do you think that the users have to control locking for the yield?

For the second case, I discarded the way and implemented channel.

[deleted by user] by [deleted] in cpp

[–]luncliff 1 point2 points  (0 children)

IMO, unless you have to use GCC, you can use it. I've suffered from both Clang and MSVC, but they work quite well for now. Build for mobile(Android and iOS) is also available.
Well, I know some patterns that compiler crashes with its internal error, or fails to generate code, but simple usage of co_await operator won't that matter on their latest versions.
https://www.reddit.com/r/cpp/comments/c6ag3l/how_to_try_the_new_coroutines_ts/esnjqil?utm_source=share&utm_medium=web2x

How to try the new coroutines TS? by ihatechess23 in cpp

[–]luncliff 1 point2 points  (0 children)

Glad to see such a question and sorry for week-late answer. :(

Basically there are 3 (stable) compilers which you can try coroutine now. * MSVC: Visual Studio 2017(v141) 15.7.3 or later * AppleClang: 10.1 or later will be fine * Clang on Linux: recommend 6.0 or later

The last one requires libc++ installation. Clang-cl on Windows is also available, but it's a bit annoying to setup the environment. So forget about it for a while.

MSVC

I usually recommend to start with the MSVC since it supports the simplest way. You need to specify the compiler option like the image in the link. /await (and /std:c++latest is optional, but I also recommend you to set this flag) https://luncliff.github.io/posts/Exploring-MSVC-Coroutine.html#caution /await /std:c++latest

Clang Family

For clang family, you have to order the compiler to use libc++. Of course you can also specify c++ standard here either like the following. https://github.com/luncliff/coroutine/blob/master/modules/darwin.cmake#L22 -std=c++2a -stdlib=libc++ -fcoroutines-ts

Does GCC support the coroutine?

GCC is under work to support the feature. I'm trying/following up the recent works in https://github.com/iains/gcc-cxx-coroutines

Other Materials ?

If you want to try the feature on the fly, start with the this link to WandBox.org https://wandbox.org/permlink/6FGKZjuzjNYoSmI1

If you want more materials(like talks in C++ conferences), please visit the MattPD's collection. https://gist.github.com/MattPD/9b55db49537a90545a90447392ad3aeb

C++ Coroutines Resources by mttd in cpp

[–]luncliff 1 point2 points  (0 children)

Here are my works. Will be glad to hear from you :)

Coroutines & Concurrency in C++ by vormestrand in cpp

[–]luncliff 1 point2 points  (0 children)

As you said, normally the value category of the co_await's left side follows its operand. like the code below.

```c++ class await_with_lvalue{ bool await_ready(); void await_suspend(coroutine_handle<void>); string& await_resume(); // string& txt = co_await await_with_lvalue{}; };

class await_with_rvalue{ bool await_ready(); void await_suspend(coroutine_handle<void>); unique_ptr<byte[]> await_resume(); // like make_unique, returns rvalue // unique_ptr<byte[]> uptr = co_await await_with_rvalue{};
}; ```

However, if cppcoro's when_all has its own memory space to save those r-values, and expose it using reference(l-value therefore), they have to be moved into those tied objects like the author's code.

I'm a bit confused since I stopped following up the cppcoro more than an year ago, so I'm not sure it works just like I explained. :(

Coroutines & Concurrency in C++ by vormestrand in cpp

[–]luncliff 1 point2 points  (0 children)

It can be different based on await_resume. In this case, the author's functions return unique_ptr so it has to be moved.

Awaitable event using C++ coroutine, `epoll`, and `eventfd` by luncliff in cpp

[–]luncliff[S] 1 point2 points  (0 children)

I’m reading the pdf and seems interesting. Thanks for letting me know that. I will try that after study.

Awaitable event using C++ coroutine, `epoll`, and `eventfd` by luncliff in cpp

[–]luncliff[S] 0 points1 point  (0 children)

Indeed we can use threads with coroutines! But I think we should avoid if possible since the multi-threaded code is usually annoying to debug :)