Ticket #8301: canonical.cpp

File canonical.cpp, 1.3 KB (added by y.hoshizuki, 10 years ago)

test program

Line 
1#include <iostream>
2#include <boost/thread.hpp>
3#include <boost/filesystem.hpp>
4
5#define MULTI_THREAD
6
7int main()
8{
9 boost::filesystem::path arg = L"test";
10
11 if( !boost::filesystem::exists( arg ) )
12 boost::filesystem::create_symlink( L"C:\\", arg );
13
14 auto core = [=]() -> boost::filesystem::path {
15 try {
16 return boost::filesystem::canonical( arg );
17 } catch( const std::exception& e ) {
18 std::cout << e.what() << std::endl;
19 return L"";
20 }
21 };
22
23 boost::packaged_task<boost::filesystem::path> task1( core );
24 boost::packaged_task<boost::filesystem::path> task2( core );
25 boost::packaged_task<boost::filesystem::path> task3( core );
26 boost::packaged_task<boost::filesystem::path> task4( core );
27
28 auto ret1 = task1.get_future();
29 auto ret2 = task2.get_future();
30 auto ret3 = task3.get_future();
31 auto ret4 = task4.get_future();
32
33#ifdef MULTI_THREAD
34 boost::thread( boost::move(task1) ).detach();
35 boost::thread( boost::move(task2) ).detach();
36 boost::thread( boost::move(task3) ).detach();
37 boost::thread( boost::move(task4) ).detach();
38#else
39 task1(); task2(); task3(); task4();
40#endif
41
42 std::cout << ret1.get() << std::endl;
43 std::cout << ret2.get() << std::endl;
44 std::cout << ret3.get() << std::endl;
45 std::cout << ret4.get() << std::endl;
46
47 return 0;
48}