<分区>
std::async 如下阻塞了我的 UI 线程,这不是我所期望的。 那么,std::async、std::promise 和 std::packaged_task 的含义是什么?
#include <iostream>
#include <thread>
#include <future>
#include "widget.h"
#include "ui_widget.h"
void func_cb()
{
for ( int i = 0; i < 1000; ++i ) {
std::cout << "do something..." << std::endl;
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
}
}
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
std::async( std::launch::async, func_cb );
}
Widget::~Widget()
{
delete ui;
}