With win32 threads I have the straight forward GetExitCodeThread()
that gives me the value which the thread function returned. I'm looking for something similar for std::thread
(or boost threads)
As I understand this can be done with futures but how exactly?
C++: Simple return value from std::thread
cmultithreading
Related Topic
- C++ – Simple example of threading in C++
- Java – “implements Runnable” vs “extends Thread” in Java
- C# – How to update the GUI from another thread
- C++ – Why is “using namespace std;” considered bad practice
- Android “Only the original thread that created a view hierarchy can touch its views.”
- C++ – Image Processing: Algorithm Improvement for ‘Coca-Cola Can’ Recognition
- C++ – std::promise
Best Answer
See this video tutorial on C++11 futures.
Explicitly with threads and futures:
Or with
std::async
(higher-level wrapper for threads and futures):I can't comment whether it works on all platforms (it seems to work on Linux, but doesn't build for me on Mac OSX with GCC 4.6.1).