stdasync Questions
2
Consider the following two snippets of code where I am trying to launch 10000 threads:
Snippet 1
std::array<std::future<void>, 10000> furArr_;
try
{
size_t index = 0;
for (auto &...
Sales asked 22/6, 2017 at 2:24
7
High level
I want to call some functions with no return value in a async mode without waiting for them to finish. If I use std::async the future object doesn't destruct until the task is over, this...
Fetich asked 3/2, 2014 at 15:23
1
Solved
I have a function that returns a std::future. I have added a cache to the implementation, and I would like to optionally return a value immediately if it does not need to be recalculated.
How can I...
Jaquelinejaquelyn asked 14/7, 2023 at 19:7
6
Solved
Can anybody give a high level intuition about when to use each of them?
References:
Is it smart to replace boost::thread and boost::mutex with c++11 equivalents?
When is it a good idea to use st...
Inquisitorial asked 12/9, 2014 at 18:15
4
Solved
While working with the threaded model of C++11, I noticed that
std::packaged_task<int(int,int)> task([](int a, int b) { return a + b; });
auto f = task.get_future();
task(2,3);
std::cout <...
Hosea asked 9/8, 2013 at 9:34
3
Solved
I got to know the reason that future returned from std::async has some special shared state through which wait on returned future happened in the destructor of future. But when we use std::pakaged_...
Mastermind asked 11/9, 2020 at 8:43
0
In the description of the std::async it is said that:
If the std::future obtained from std::async is not moved from or bound
to a reference, the destructor of the std::future will block at the
end...
Trichiasis asked 12/8, 2020 at 22:7
1
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 m...
5
Solved
I'm trying to explore all the options of the new C++11 standard in depth, while using std::async and reading its definition, I noticed 2 things, at least under Linux with gcc 4.8.1:
It's called as...
Semifinal asked 31/7, 2013 at 6:30
1
Solved
The idea behind a deferred future (achieved only by calling std::async with std::launch::deferred flag) is that the callback is called only when someone tries to wait or to pull the futuristic valu...
Fourpenny asked 21/7, 2018 at 9:31
5
Solved
Running this code from Herb Sutter's presentation. This works fine in linux under gcc 4.6.3. I'm thinking that future.h isn't supported in mingw, but the error is really hard to understand!
#inclu...
Frowst asked 18/4, 2012 at 12:58
2
Solved
It appears that arguments of a function executed via std::async share the lifetime of the future:
#include <iostream>
#include <future>
#include <thread>
struct S
{
S() {
std:...
7
Solved
Per [futures.async]/3 bullet 1 of the C++ Standard, when a function f is passed to std::async with the std::launch::async launch policy, f will run "as if in a new thread of execution".
Given tha...
Unfrequented asked 7/5, 2018 at 19:19
3
I am using std::async to create a thread, I want this new thread should execute separately and main thread should not wait for it. But here when I call std::async, a new thread is created but...
Sparteine asked 2/2, 2018 at 3:42
1
Visual C++ uses the Windows thread pool (Vista's CreateThreadpoolWork if available and QueueUserWorkItem if not) when calling std::async with std::launch::async.
The number of threads in the pool i...
Octa asked 12/3, 2017 at 23:1
1
Solved
I am quite new to the C++11 feature std::async and I fail to grasp why the code below never prints bar.
Could someone shed some light on this for me?
class Thready {
public:
Thready() {
std...
Holpen asked 13/10, 2016 at 20:30
2
Solved
I've been told several times, that I should use std::async for fire & forget type of tasks with the std::launch::async parameter (so it does it's magic on a new thread of execution preferably)....
Imminent asked 21/5, 2016 at 12:24
1
Solved
I believed it was better to process simple and heavy works (ex. matrix-calculation) with multi-threading than with single-thread, so I tested the following code :
int main()
{
constexpr int N = ...
Pottage asked 27/2, 2016 at 5:29
1
Solved
I've wrote the following code to test std::async() on functions returning void with GCC 4.8.2 on Ubuntu.
#include <future>
#include <iostream>
void functionTBC()
{
std::cerr <<...
Skiba asked 29/5, 2015 at 16:52
1
Solved
I am trying to create a thread using std::async, but I keep getting the error
"no matching function for call to ‘async(std::launch, <unresolved overloaded function type>, std::string&)’"...
2
Solved
Near the beginning of this clip from C++ And Beyond, I heard something about problems with std::async. I have two questions:
For a junior developer, is there a set of rules for what to do and wha...
Sousa asked 20/9, 2012 at 8:19
2
Solved
Consider following code
void printPromised(std::future<int> f)
{
std::cout << f.get() << std::endl;
}
int main()
{
printPromised(std::async(std::launch::async, [](){ return 8; ...
2
Solved
Possible Duplicate:
std::bind overload resolution
Consider following C++ example
class A
{
public:
int foo(int a, int b);
int foo(int a, double b);
};
int main()
{
A a;
auto f = std::...
Must asked 20/11, 2014 at 6:44
2
How can I, or, can I, pass a template function to async?
Here is the code:
//main.cpp
#include <future>
#include <vector>
#include <iostream>
#include <numeric>
int
main
...
1
Solved
Is it possible to call function objects created with std::bind using std::async. The following code fails to compile:
#include <iostream>
#include <future>
#include <functional>
...
Commutator asked 29/9, 2013 at 14:28
1 Next >
© 2022 - 2024 — McMap. All rights reserved.