I want to run some bunch of codes asynchronously in c++. This is for an gtk GUI application. I want to get the length from a encoder to an variable while running the other parts of the code. This lines of code should be always running. When i want the length, i should be able to get the current length from the variable. Can any one help me on this.
Asked
Active
Viewed 257 times
0
-
Does this answer your question? [When to use std::async vs std::threads?](https://stackoverflow.com/questions/25814365/when-to-use-stdasync-vs-stdthreads) – pptaszni Aug 19 '21 at 14:29
1 Answers
2
I haven't understood what exactly you want to do. But I think you can read more about the std::async.
#include <iostream>
#include <future>
void asyncFunction ()
{
std::cout << "I am inside async function\n";
}
int main()
{
std::future<void> fn = std::async(std::launch::async, asyncFunction);
// here some other main thread operations
return 0;
}
Function that is run asynchronously can also return a value, which can be accessed through the future with std::future::get
blocking method.

pptaszni
- 5,591
- 5
- 27
- 43

Hitesh Patil
- 86
- 8
-
1I don't think this is an answer because all the problems with notifying the run loop is still left out and thats also the most important part. – Lothar Aug 21 '21 at 19:38