

Учись благодаря многочисленным ресурсам, которые есть на Docsity
Заработай баллы, помогая другим студентам, или приобретай их по тарифом Премиум
Эта страница недоступна для предварительного просмотра
Не пропусти важные части!


std::future submitForm(const std::string& form) { auto handle = [](const std::string& form) -> bool { std::cout << "Handle the submitted form: " << form << "\n"; return true; }; std::packaged_task task(handle); auto future = task.get_future(); std::thread thread(std::move(task), form); thread.detach(); return std::move(future); }
std::future submitForm(const std::string& form) { auto handle = [](const std::string& form) -> bool { std::cout << "Handle the submitted form: " << form << "\n"; return true; }; std::packaged_task task(handle); task.make_ready_at_thread_exit(form); return task.get_future(); }
int main() {
auto check = submitForm("My Form"); if (check.get()) std::cout << "Wow I've got a passport! \n"; else std::cout << "Dammit, they found a mistake again! \n"; }
#include #include #include #include #include int main() { std::cout << "Main thread id=" << std::this_thread::get_id() << "\n"; auto asyncDefault = std::async( { std::cout << "Async default, Threadid=" << std::this_thread::get_id() << "\n"; }); auto asyncDeffered = std::async(std::launch::deferred, [](const std::string& str) { std::cout << "Async deffer, Threadid=" << std::this_thread::get_id() << "," << str << "\n"; }, std::string("end string")); auto asyncDeffered2 = std::async(std::launch::deferred, { std::cout << "Async deffer2, Threadid="