久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

C++:來自 std::thread 的簡單返回值?

C++: Simple return value from std::thread?(C++:來自 std::thread 的簡單返回值?)
本文介紹了C++:來自 std::thread 的簡單返回值?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

使用 win32 線程,我可以直接使用 GetExitCodeThread() 來獲取線程函數返回的值.我正在為 std::thread(或 boost 線程)尋找類似的東西
據我所知,這可以通過期貨來完成,但究竟如何?

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++11 期貨的視頻教程.

明確使用線程和期貨:

#include <thread>
#include <future>

void func(std::promise<int> && p) {
    p.set_value(1);
}

std::promise<int> p;
auto f = p.get_future();
std::thread t(&func, std::move(p));
t.join();
int i = f.get();

或者使用 std::async(線程和期貨的高級包裝器):

Or with std::async (higher-level wrapper for threads and futures):

#include <thread>
#include <future>
int func() { return 1; }
std::future<int> ret = std::async(&func);
int i = ret.get();

我無法評論它是否適用于所有平臺(它似乎適用于 Linux,但不適用于我使用 GCC 4.6.1 的 Mac OSX).

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).

這篇關于C++:來自 std::thread 的簡單返回值?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

What is the fastest way to transpose a matrix in C++?(在 C++ 中轉置矩陣的最快方法是什么?)
Sorting zipped (locked) containers in C++ using boost or the STL(使用 boost 或 STL 在 C++ 中對壓縮(鎖定)容器進行排序)
Rotating a point about another point (2D)(圍繞另一個點旋轉一個點 (2D))
Image Processing: Algorithm Improvement for #39;Coca-Cola Can#39; Recognition(圖像處理:Coca-Cola Can 識別的算法改進)
How do I construct an ISO 8601 datetime in C++?(如何在 C++ 中構建 ISO 8601 日期時間?)
Sort list using STL sort function(使用 STL 排序功能對列表進行排序)
主站蜘蛛池模板: 欧美成人一区二区三区 | 久久久性色精品国产免费观看 | 国产伦精品一区二区三区照片91 | 亚洲天堂av在线 | 黄色精品视频网站 | 欧洲一区二区三区 | 国产精品国产a | 午夜精品在线观看 | 久久在线精品 | 羞羞网站在线免费观看 | 国产黄色网 | 亚洲国产精品精华素 | 欧美色图另类 | 欧美日韩在线观看视频 | 国产精品国产a级 | 久久久www | 一区二区三区日韩 | 在线播放亚洲 | 欧美一级免费 | 97精品国产97久久久久久免费 | 一级欧美一级日韩片免费观看 | 男女啪啪高潮无遮挡免费动态 | 一区二区三区四区在线免费观看 | 黄色大片免费看 | 久久久久久免费毛片精品 | 国产精品夜夜夜一区二区三区尤 | 亚洲黄色av | 一区二区在线看 | 一区在线观看 | 久久国产精品-久久精品 | 亚洲国产日韩欧美 | jlzzjlzz国产精品久久 | 久久久中文 | 国产日韩一区二区三免费高清 | 国产高清在线视频 | 成年免费大片黄在线观看岛国 | 91av入口| 中文字幕一区二区三区精彩视频 | 天天摸天天干 | 日韩一级免费观看 | 91在线免费视频 |