#include #include #include #define MULTI_THREAD int main() { boost::filesystem::path arg = L"test"; if( !boost::filesystem::exists( arg ) ) boost::filesystem::create_symlink( L"C:\\", arg ); auto core = [=]() -> boost::filesystem::path { try { return boost::filesystem::canonical( arg ); } catch( const std::exception& e ) { std::cout << e.what() << std::endl; return L""; } }; boost::packaged_task task1( core ); boost::packaged_task task2( core ); boost::packaged_task task3( core ); boost::packaged_task task4( core ); auto ret1 = task1.get_future(); auto ret2 = task2.get_future(); auto ret3 = task3.get_future(); auto ret4 = task4.get_future(); #ifdef MULTI_THREAD boost::thread( boost::move(task1) ).detach(); boost::thread( boost::move(task2) ).detach(); boost::thread( boost::move(task3) ).detach(); boost::thread( boost::move(task4) ).detach(); #else task1(); task2(); task3(); task4(); #endif std::cout << ret1.get() << std::endl; std::cout << ret2.get() << std::endl; std::cout << ret3.get() << std::endl; std::cout << ret4.get() << std::endl; return 0; }