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

C++17 async: running a this' method blocks the whole object

I'm developing a game. Lets say theres an object LoadingState with these methods (and some others): create update load The update is called every time the CPUs clock ticks, whilst the create will be called only once and it should call the load…
Yves Calaci
  • 1,019
  • 1
  • 11
  • 37
0
votes
1 answer

Coudn't run code used std::async on GCC 5.3.0

I was practicing std::asyn function that introduced in c++11, I wrote a simple example #include #include using namespace std; void check() { cout<<"some"<
RaGa__M
  • 2,550
  • 1
  • 23
  • 44
0
votes
1 answer

std::thread to std::async makes HUGE performance gain. How it can be possible?

I`ve made a test code between std::thread and std::async. #include #include #include #include #include #include #include #include #include #include…
Byoungchan Lee
  • 1,372
  • 13
  • 28
0
votes
1 answer

error in async function

I want to test the following function with std::async for a static class and my main aim is to wait untill the function executes. But i am facing the following error. Can some one give me a reason for this error. IASD* ASDInterface = getASD();//gets…
0
votes
1 answer

How can I pass in a variable to a std::async?

How can I pass in a vector to an async call like so?? std::vector vectorofInts; vectorofInts.push_back(1); vectorofInts.push_back(2); vectorofInts.push_back(3); std::async([=] { //I want to access the vector in here, how do I pass it in …
Harry Boy
  • 4,159
  • 17
  • 71
  • 122
0
votes
1 answer

How to asynchronously execute method from unique_ptr to object?

I have created a unique pointer to an object like this: std::unique_ptr myObj(new MyClass(arg1, arg2)); And there is a method there, which I need to execute in a parallel thread. I do not want to wait for it to finish. It will run a for…
Subhamoy S.
  • 6,566
  • 10
  • 37
  • 53
0
votes
1 answer

std::async returning value. Unknown Error

I´m working with the windows Kinect in c++. I am trying to check if the right Hand went from the right to the left shoulder, like a wiping move. I´m trying to work with std::async because I need the returning value of the method. I already googled…
Spirit
  • 43
  • 1
  • 7
0
votes
1 answer

standard C++ TCP socket, connect fails with EINTR when using std::async

I am having trouble using the std::async to have tasks execute in parallel when the task involves a socket. My program is a simple TCP socket server written in standard C++ for Linux. When a client connects, a dedicated port is opened and separate…
-1
votes
0 answers

std::async having far worse performance than single threaded

I'm currently playing a bit with std::async since I read that it performs better than std::thread. I wrote a simple program with a function ("waitsome") that takes on my computer roughly 500ms to compute. If I feed this into std::async however (and…
MAPster
  • 68
  • 6
-1
votes
1 answer

return in functions with std::async

I have a function that should always return A[0][1]. But I use std::async and gcc says: test_fibonacci_method/1/main.cpp:147:1: warning: control reaches end of non-void function [-Wreturn-type] Integer Fib_iterative_n_Matrix(const unsigned& n) { …
B. A. Sylla
  • 419
  • 3
  • 13
-1
votes
1 answer

std::async is causing segmentation fault (or slow)

i have written simple class to solve system of linear equations , to parallelize the matrix row subtractions i used std::async . after size of 10x10 matrix the program is crashing due to segmentation fault. my first implementation was to replace …
Barath Keshav
  • 121
  • 1
  • 6
-1
votes
2 answers

Can't launch asynchronnously a function with object argument

How can I pass an object to a function which is started asynchronously? #include #include class SomeObject { void Dummy(); } class A { public: void Test1(); void Test2(SomeObject o); void…
query
  • 329
  • 7
  • 18
-6
votes
2 answers

What's the difference between passing a function directly to std::async and using std::bind?

I recently started adding async support to a library I'm working on, but I hit a slight problem. I started off with something like this (full context later): return executeRequest(false, d, &callback, false); That was before adding async…
Zoe
  • 27,060
  • 21
  • 118
  • 148
1 2 3
10
11