2,398 questions
18
votes
1
answer
2k
views
Whose responsibility is it to destroy a C++20 coroutine that throws from its initial suspend?
I am trying to track if a C++20 coroutine has ever suspended, so that unhandled_exception knows whether it can simply re-throw; the exception back to the caller of the initial coroutine function, or ...
1
vote
4
answers
97
views
Why only creating a task will run the coroutine in python?
There is something I can't understand in this code
import asyncio
async def fetch_data(param):
print(f"Do something with {param}...")
await asyncio.sleep(param)
print(f"Done ...
2
votes
1
answer
180
views
boost.asio : how to cancel a synchronous task
The following code simulates short bursts of work by sleeping 1ms at a time in order to achieve a cancellable task that takes a total of 2s. That work is then launched in three different ways.
The ...
5
votes
1
answer
392
views
How to use C++ coroutine with Qt?
I am trying to use coroutines with Qt.
Here's minimal(I guess) example to reproduce my problem
Basically, bellow code is adopted from the example of cppreference here:
https://en.cppreference.com/w/...
1
vote
1
answer
175
views
Why calling longjmp in a non-main stack causes the program to crash?
The following code attempts to create a simple stackful coroutine. It allocates a stack frame in the heap space by setting the rsp register and then calling a function. Afterwards, it exits the ...
2
votes
0
answers
68
views
How can I dynamically trace and visualize memory allocation patterns of nested Python coroutines in real-time?
I'm trying to understand how memory is used in my async Python application. I have multiple coroutines running, and I want to see how much memory each one is using, especially when they are nested or ...
0
votes
1
answer
91
views
How does async / await work, in a simplified abstract sense?
I am trying to understand how async / await works from a high-level, semi-abstract perspective.
There are quite a few long and complicated explanations of async / await online, some of which appear ...
1
vote
0
answers
112
views
Coroutine with RAII using Boost.Asio
I'm writing some test code using Boost.Asio with C++20 coroutines.
Working version (manual cleanup, non-RAII)
The following code works as expected. Cleanup is always called, even when an exception is ...
-1
votes
1
answer
167
views
What is the idiomatic way for a coroutine to release a strand?
Let's assume I have a coroutine running on a strand. I would like the completion to be posted to the parent executor of the strand (i.e. : a thread_pool) while also releasing the strand. What is the ...
1
vote
0
answers
90
views
Lua preemptive multitasking and supporting nested coroutines
I am trying to write a scheduler for a virtual computer that runs Lua and is transparent to the user (i.e.; no coroutine. yields needed) and would still like the user to be able to create coroutines ...
2
votes
1
answer
125
views
declare return_void / return_value conditionally
I've tried std::enable_if and requires:
template <typename Ret>
struct promise_type {
auto get_return_object() {/*...*/}
auto initial_suspend() {/*...*/}
auto return_void()
-> std:...
3
votes
1
answer
107
views
Are `std::noop_coroutine` and `noop_coroutine_handle` redundant?
In GCC 15, std::noop_coroutine's definition is
{ return std::noop_coroutine_handle(); }
std::noop_coroutine_handle is defined by:
using noop_coroutine_handle = std::coroutine_handle<std::...
2
votes
0
answers
92
views
C++ Coroutine task class strange issue
Basically, the whole idea is something like the Task implementation in C# where functions can return Task<T> that callers can await on. For some reason, TestFuncAsync runs correctly the first 2 ...
-7
votes
1
answer
267
views
Are Cgo implementing functions allowed to arbitrarily manipulate the stack pointer? [closed]
I would like to know whether Cgo implementing functions are allowed to arbitrarily manipulate the stack pointer. The motivation for this is to allow the use of coroutines on the C side of the call. ...
0
votes
0
answers
77
views
When is `async for` faster than `for` (python)?
In python, one can replace for [...] in [generator] by async for [...] in [awaitable generator]. Clearly, this lowers the overall execution time of a program if the [generator] contains some slow I/O ...
0
votes
1
answer
60
views
Android, how to print out coroutine id or name on a custom log function
I want to modify this log helper function to print out coroutine id or name.
@JvmInline
value class MyLogger(private val tag: String) {
fun log(level: Level, e: Throwable? = null, ...
4
votes
1
answer
158
views
C++ is std::generator thread safe?
I've read through the documentation of std::generator<T> and found no mention of thread-safety.
Now essentially I have a co-routine that generates work elements and I want to consume them with ...
1
vote
1
answer
100
views
Does the call instruction write something onto the stack? For example, things like environment variables?
I am currently running a C++ program in which I have used the heap to simulate the stack and employed assembly language to place relevant information (such as memory addresses) into registers, thereby ...
0
votes
2
answers
64
views
When I add a if condition to my coroutine which starts a decrease in value of oxygen, it makes it deplete really fast
I wanted to add a if condition to my coroutine and it broke it
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Water"))
{
isSwimming = true;
rb....
1
vote
1
answer
72
views
C++ Profiling - Called method from coroutine function has a higher hit count than its caller
I am profiling some code using the cppgraphgqlgen library - which uses C++20 coroutines extensively in its internals.
I have profiled an application and found that I have some called-into methods that ...
2
votes
1
answer
61
views
Why intermediate coroutine hangs up top level coroutine?
Where is task to process big list of items in sequential-parallel way: split big list to chunks, process chunks one after another, process items from each chunk in parallel.
Implementing this task, I ...
1
vote
3
answers
134
views
Asyncio future, running Future objects
I have a code:
import asyncio as aio
async def coro(future: aio.Future):
print('Coro start')
await aio.sleep(3)
print('Coro finish')
future.set_result('coro result')
async def main():
...
3
votes
1
answer
191
views
Is it possible to create a C++ coroutine task/promise type that makes it possible to get_running_coroutine()?
AFAICT there is no builtin way in C++20 or C++23 to globally query the promise or handle for the coroutine running on the current thread. However any of the functions that let you return a coroutine ...
0
votes
0
answers
49
views
PyQt5 Application with PythonTelegramBot (PTB) coroutine
I'm struggling with running python-telegram-bot-21.10 as a coroutine to a PyQt5 application using Python-3.12.7 (intended to run on a Raspberry Pi).
I had this setting operating for some years now ...
3
votes
1
answer
91
views
C++ coroutine destruction order
This article presents this pseudocode for how the compiler transforms a coroutine function:
ReturnType someCoroutine(Parameters parameter)
{
auto* frame = new coroutineFrame(std::forward<...
2
votes
1
answer
55
views
Can Lua define anonymous member functions?
In Lua, I can define a member function like this:
Foo = {}
function Foo:bar()
...
end
I realise this is just syntactic sugar for this:
Foo = {}
foo.bar = function(self)
...
end
Is there a way ...
6
votes
2
answers
2k
views
Issue with Google Sign-In Implementation in ViewModel
I'm facing an issue with my Google Sign-In implementation in an Android application. I have two pieces of code: the first one works correctly, while the second one fails during the call to ...
2
votes
1
answer
121
views
Why do coroutines need less memory than threads?
It is often said that coroutines could be thought of as "light threads" because they consume less memory. However, I wasn't able to find any explanation on why exactly that is the case. What ...
1
vote
0
answers
81
views
Are There More Efficient Awaiters for C++ Coroutines Than std::suspend_always?
I’m attempting to optimize a binary search workload using C++ coroutines on a 1GB sorted array of unique random integers to induce multiple memory misses. The approach involves using co_await when ...
1
vote
1
answer
144
views
how we can pass values to a coroutine
I want to know a method to pass values from the caller to the coroutine.
My idea:
Any awaiter type must provide a await_resume() function. This function can return something to the co_await inside ...
-1
votes
1
answer
68
views
Using coroutines and loops to have a repeatable delay in Unity?
I'm very new to coding and am trying to make a basic simon says game. Currently I have a cube that is supposed to change the material after a few seconds however I'm really struggling getting any sort ...
0
votes
0
answers
96
views
Is there a clean way to template match lvalue or value but not rvalue?
So far the best I've come up with is a wrapper function for every function, like this:
template<class A, class B>
coro<var> operator+(A && a, B && b)
{
return [] (A a, ...
0
votes
0
answers
56
views
MongoDB Kotlin Driver : Client timeout after a few hours
I'm using the MongoDB Kotlin Driver dependency.
My project run with Spring Boot but I don't want to use the Spring Data MongoDB dependency (So as not to be dependant on Spring).
I use a bean to ...
2
votes
0
answers
159
views
What's wrong with my implementation of c-style coroutine
I try to implement a simple coroutine using c.
The platform is:
M3 Pro MacBook Pro 16
apple native gcc
macOS 14.3.1
Here is my code:
// main.c
#include <stdio.h>
#include <stdlib.h>
#...
2
votes
0
answers
80
views
Can't receive messge in IPC Communication
I have a server and a client. The server is responsible for forking child processes and interacting with them to get log outputs to send to the client. It also receives input from the client and sends ...
2
votes
2
answers
117
views
c++ coroutine, done() function returns different value in a same loop
godbolt: https://godbolt.org/z/6avWcGqKv
The following code, compiled and run with g++ 12, 13, 14, all give the same (wrong?) output.
clang 18, 19 are fine (all "done: 1").
As far as I ...
2
votes
3
answers
177
views
coroutine_handle resume call from thread vs jthread
I have implemented my own experimental coroutine awaiter object to grasp the awaiter rationale.
I call a coroutine which is foo in my example. In await_suspend method, I invoked a thread and this ...
1
vote
1
answer
51
views
coroutine_handle::done always returns false
I have a very simple coroutine example to understand basics. However, I am stuck to understand why the done method of the handle object still returns false. I call resume and there is no more co_await ...
-1
votes
1
answer
68
views
What's the idiomatic way to waste the output of a generator in Python? [duplicate]
Sometimes I need to consume everything that a generator outputs but don't actually need the output. In one case, some callers need progress updates from a coroutine, but some callers don't; in another ...
0
votes
1
answer
164
views
How to force 2 coroutines never run simultaneously
In this code:
private suspend fun doSthSingleThreaded(){
coroutineScope {
//Coroutine 1
launch {
//do sth that will suspend
}
//Coroutine 2
...
0
votes
1
answer
129
views
Why setting parent coroutineContext.job to Job() does not cause children to be cancelled?
In the following code, I build a coroutine in scope1 using launch. I set its job to be instance of Job, so any children's cancellation will cause the parent job to be cancelled.
I used awaitAll which, ...
1
vote
0
answers
45
views
Isn't stacking suspend'able functions a performance killer?
While diving into Android/Kotlin development, I learned that the suspend keyword transforms the function into a state machine that can be removed from its executing thread, put on hold, and resumed at ...
3
votes
2
answers
132
views
Coroutine callback late bound i.e. std::function, indirect co_await
I got a processing class that signals a certain condition via a callback that is bound late at runtime. The processing class is executed by a coroutine, and the signal wants to call a coroutine ...
1
vote
3
answers
104
views
how to catch throw and other exceptions in coroutine with 1 yield?
I have var DICTIONARY, which is a dictionary where the keys are English letters and the values are words that start with the corresponding letter. The initial filling of DICTIONARY looks like this:
...
-1
votes
1
answer
48
views
how to generate correct output using 2 yield statements in coroutine?
i have var DICTIONARY, which is a dictionary where the keys are English letters and the values are words that start with the corresponding letter. The initial filling of DICTIONARY looks like this:
...
0
votes
0
answers
47
views
Function works but coroutine doesn´t
I have a really weird bug where I have a function that resets my whole room. First, it clears the previous grids if they exist. Then, it generates lists of lists of vectors, which work as grids. Then ...
0
votes
0
answers
60
views
In the Unity Engine, the member field referenced by the coroutine becomes NULL
This code works fine.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
class Enemy
{
public string enemyName = "Default Enemy Name&...
0
votes
1
answer
79
views
How to test SnapshotStateList being updated
I have
class MyViewModel(private val activitiesRepo: ActivitiesRepo) : ViewModel() {
val activities = mutableStateListOf<Activity>()
private var activitiesFlow =
activitiesRepo....
1
vote
1
answer
279
views
How to run a Lua coroutine in C++ with sol3?
I'm using sol2 (v3.3.0) in C++ to run Lua coroutines. I want to pass a Lua function to C++ and execute it as a coroutine. However, my attempts to convert sol::function to sol::coroutine are not ...
3
votes
1
answer
96
views
Why can't I read from the stdout/stderr of a process spawned with forkpty in the C++20 coroutines + Asio single-threaded multi-coroutine model?
I am new to corotine and asio.
I am working on a local process management tool where a client is responsible for launching a program. This client sends commands to a backend daemon that manages the ...