c++-coroutine

Lambda lifetime explanation for C++20 coroutines

折月煮酒 提交于 2020-03-20 06:16:30
问题 Folly has a useable library for C++20 style coroutines. In the Readme it claims: IMPORTANT: You need to be very careful about the lifetimes of temporary lambda objects. Invoking a lambda coroutine returns a folly::coro::Task that captures a reference to the lambda and so if the returned Task is not immediately co_awaited then the task will be left with a dangling reference when the temporary lambda goes out of scope. I tried to make a MCVE for the example they provided, and was confused about

Why should I use coroutine in C/C++

风格不统一 提交于 2019-12-08 12:45:49
问题 this image comes from Practical usage of setjmp and longjmp in C. From my understanding, the coroutine is two process looks like doing parallelly for human but actually doing a single process for machine . But using setjmp & longjmp I feel very hard to read the code. If need to write the same one. For example process A & B, I will give serval States to the processes to split them into different pieces(states), do sequentially like: Process A switch (state) case A1: if (A1 is done) do B1 break