Questions tagged [stdasync]

The C++11 function template std::async() provides a mechanism to launch a function potentially in a new thread and provides the result of the function in a future object.

C++11 provides the function template std::async() as a simple tool for running functions asynchronously. Its parameters are a callable object and an optional list of arguments and its return type is an instantiation of the std::future class template.

Rather than invoking the target object immediately it will be called asynchronously, either in a new thread or deferred until the result is needed. The std::future object can be used to retrieve the result of the asynchronous call or any exceptions it throws.

The initial proposals for std::async() were N2889 An Asynchronous Call for C++ and A simple async().

See also

163 questions
0
votes
1 answer

Boost:asio and async in multi-threading

I need to call method which is a request for a remote server. After that i want to wait for an answer, and waiting is not blocked by other asynchronous function/objects(timers for example). Method got_response(...) tells user that he got an answer…
5133n
  • 11
  • 1
  • 3
0
votes
1 answer

Is it correct to use std::async for background tasks inside an internal thread (not from main process's thread)

I would like to have your opinion for this general technical concept. (I am working on microsoft windows OS) There is a Process, this process creates multiple threads for different tasks. Main process: it is a windows service written by C#…
0
votes
1 answer

`std::async` for asynchronous replies in C++

Overview : I have a client-server implementation, which uses DBus(sdbus-c++) to send asynchronous requests to a server. Now my server interacts with hardware APIs which behaves synchronously and also takes significant time to generate a reply. So I…
gst
  • 1,251
  • 1
  • 14
  • 32
0
votes
0 answers

recursive function with std::async stuck from some size of std::vector

I rewrite function who get all combination of vector. I tried to run it asynchronously, when the vector size is 5 - getAllCombinationOfVector({ 1,2,3,4,5}) it work fine. when the vector size is 6 it stuck. When the input is 6 the code never reach to…
0
votes
0 answers

std::async is very slow

i have successfully multithreaded my code but the result is very slow , i there are no thread conflict and yet i am getting very slow code. the program is to use gaussian elimination to solve system of equations , and i have used async to…
Barath Keshav
  • 121
  • 1
  • 6
0
votes
1 answer

Is there any way to speedup the future.get() function after launching the std::async function in a multithreaded environment?

I have a correctly working code to process 1000 image files using openCV. As the operation is independent of individual files, I have used multithreading using the std::async function. I am launching the threads by following function call inside for…
The White Cloud
  • 189
  • 1
  • 11
0
votes
0 answers

Why am I getting a "read access violation" exception thrown while accessing value from std::future?

Edit: my question is different from the suggested question becaude I cannot poll 100's of future.get() and wait to execute the remaining program in main() thread. I am hoping the threads to return the value when the thread is done executing and…
The White Cloud
  • 189
  • 1
  • 11
0
votes
1 answer

How to use std::async with void method with no parameters?

I'm assuming there's something very simple I'm missing about std::async. I'm trying to run 2 void methods asynchronously, with no return values. #include class AsyncTestClass { public: void Initialize() { …
Eric Smith
  • 35
  • 6
0
votes
0 answers

Gracefully exit a program containing std::async C++

I have the main thread, which calls a function using std:async. void fileIO() { while (true) { SomeClass::someStaticFunction(); } } int main() { ... ... std::future fileIOFuture = async(std::launch::async, fileIO); …
coda
  • 2,188
  • 2
  • 22
  • 26
0
votes
1 answer

Why am I Getting error in async, future in C++

I am using std::async and std::future for the first time and am getting the error, Can somone help me rectify it. The error: ** terminate called after throwing an instance of 'std::future_error' what(): std::future_error: No associated state** The…
0
votes
1 answer

Can I change a std::sync(std::launch::deferred policy to std::launch::async, once created?

I'm in a scenario where I have many I/O-bound tasks, nicely suited to run in background. However, I can't launch all of them in parallel. Although I could use other tricks (eg. count semaphores), I wonder if I could change an already created…
olepinto
  • 351
  • 3
  • 8
0
votes
1 answer

What is the semantics of std::async with automatic (launch::async|launch::deferred) launch policy?

The std::async has two overloads, one of them makes the parameter std::launch policy explicit while the other omits this parameter. The policy is a bitmask, so both launch::async|launch::deferred may be specified (or you may avoid the policy using…
Dmitry Kuzminov
  • 6,180
  • 6
  • 18
  • 40
0
votes
4 answers

do I have to call get or wait on a std::async future

If I run it with launch::async then I know it will run anyway (I think thats what I read), but do I have to call get / wait in order to perform some sort of clean up. I dont need the result, I just want a nice fire and forget.
pm100
  • 48,078
  • 23
  • 82
  • 145
0
votes
0 answers

member variable in std::async thread

I am working on a project in which I am using threads. The threads are launched with std::async and I ran into some things with member variables in a class that I do not understand. In the code below there are four different implementations of the…
Mats
  • 69
  • 1
  • 9
0
votes
1 answer

C++ std::thread and std::async tests are in progress, but an error occurs

I am trying to identify the difference between std::::thread and std:async through a simple experiment.(check std::async Thread Pool functionality) However, an error occurs during execution. What's the problem and how can I fix it? thread…
Hwan E
  • 566
  • 2
  • 13