本文整理汇总了C++中Promise::GetFuture方法的典型用法代码示例。如果您正苦于以下问题:C++ Promise::GetFuture方法的具体用法?C++ Promise::GetFuture怎么用?C++ Promise::GetFuture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Promise
的用法示例。
在下文中一共展示了Promise::GetFuture方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
// simple one-thread example
/*Promise<int> pr;
Future<int> check = pr.GetFuture();
pr.SetValue( inc( 10 ) );
int res = check.Get();
if( res )
std::cout << "Success\n" << res;
else
std::cout << "Error\n";*/
// 2-threads example
Promise<int> pr;
Future<int> check = pr.GetFuture();
unsigned threadID;
HANDLE hThread = ( HANDLE ) _beginthreadex( NULL, 0, &SecondThreadFunc, &check, 0, &threadID );
pr.SetValue( 7 ); // If this string is commented, setted value won't be printed
WaitForSingleObject( hThread, INFINITE );
CloseHandle( hThread );
// asynch example
std::function<int(void)> f11 = std::bind( inc, 11 );
std::function<int(void)> f13 = std::bind( inc, 13 );
std::function<int(void)> f19 = std::bind( inc, 19 );
Future<int> fut11 = async<int>( &f11, 0 );
Future<int> fut13 = async<int>( &f13, 0 );
Future<int> fut19 = async<int>( &f19, 1 );
std::cout << "####### Yeap, I've done it! " << fut11.Get() << ". And again: " << fut13.Get() << std::endl;
std::cout << "####### Synch: " << fut19.Get() << std::endl;
/*
// callAfter example
Promise<int> pr1;
Promise<int> pr2;
Promise<int> pr3;
Future<int> f1 = pr1.GetFuture();
Future<int> f2 = pr2.GetFuture();
Future<int> f3 = pr3.GetFuture();
pr1.SetValue( 55 );
pr2.SetValue( 65 );
pr3.SetValue( 75 );
f3.callAfter( f2.callAfter( f1 ) );
std::cout << "####### callAfter values: " << f1.Get() << " " << f2.Get() << " " << f3.Get() << std::endl;*/
return 0;
}