Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / thread / test / sync / futures / async / async_pass.cpp
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // Copyright (C) 2011 Vicente J. Botet Escriba
11 //
12 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
13 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
14
15 // <boost/thread/future.hpp>
16
17 // template <class F, class... Args>
18 //     future<typename result_of<F(Args...)>::type>
19 //     async(F&& f, Args&&... args);
20
21 // template <class F, class... Args>
22 //     future<typename result_of<F(Args...)>::type>
23 //     async(launch policy, F&& f, Args&&... args);
24
25 //#define BOOST_THREAD_VERSION 3
26 #define BOOST_THREAD_VERSION 4
27 #include <boost/config.hpp>
28 #if ! defined  BOOST_NO_CXX11_DECLTYPE
29 #define BOOST_RESULT_OF_USE_DECLTYPE
30 #endif
31 #include <iostream>
32 #include <boost/thread/future.hpp>
33 #include <boost/thread/thread.hpp>
34 #include <boost/thread/detail/memory.hpp>
35 #include <boost/thread/csbl/memory/unique_ptr.hpp>
36 #include <memory>
37 #include <boost/detail/lightweight_test.hpp>
38
39 typedef boost::chrono::high_resolution_clock Clock;
40 typedef boost::chrono::milliseconds ms;
41
42 class A
43 {
44   long data_;
45
46 public:
47   typedef long result_type;
48
49   explicit A(long i) :
50     data_(i)
51   {
52   }
53
54   long doit() const
55   {
56     boost::this_thread::sleep_for(ms(200));
57     return data_;
58   }
59   long operator()() const
60   {
61     boost::this_thread::sleep_for(ms(200));
62     return data_;
63   }
64 };
65
66 class MoveOnly
67 {
68 public:
69   typedef int result_type;
70
71   int value;
72
73   BOOST_THREAD_MOVABLE_ONLY(MoveOnly)
74   MoveOnly()
75   {
76     value = 0;
77   }
78   MoveOnly( BOOST_THREAD_RV_REF(MoveOnly))
79   {
80     value = 1;
81   }
82   MoveOnly& operator=(BOOST_THREAD_RV_REF(MoveOnly))
83   {
84     value = 2;
85     return *this;
86   }
87
88   int operator()()
89   {
90     boost::this_thread::sleep_for(ms(200));
91     return 3;
92   }
93   template <typename OS>
94   friend OS& operator<<(OS& os, MoveOnly const& v)
95   {
96     os << v.value;
97     return os;
98   }
99 };
100
101 namespace boost
102 {
103   BOOST_THREAD_DCL_MOVABLE    (MoveOnly)
104 }
105
106 int f0()
107 {
108   boost::this_thread::sleep_for(ms(200));
109   return 3;
110 }
111
112 int i = 0;
113
114 int& f1()
115 {
116   boost::this_thread::sleep_for(ms(200));
117   return i;
118 }
119
120 void f2()
121 {
122   boost::this_thread::sleep_for(ms(200));
123 }
124
125 boost::csbl::unique_ptr<int> f3_0()
126 {
127   boost::this_thread::sleep_for(ms(200));
128   boost::csbl::unique_ptr<int> r( (new int(3)));
129   return boost::move(r);
130 }
131 MoveOnly f3_1()
132 {
133   boost::this_thread::sleep_for(ms(200));
134   MoveOnly r;
135   return boost::move(r);
136 }
137
138 boost::csbl::unique_ptr<int> f3(int i)
139 {
140   boost::this_thread::sleep_for(ms(200));
141   return boost::csbl::unique_ptr<int>(new int(i));
142 }
143
144 boost::csbl::unique_ptr<int> f4(
145     BOOST_THREAD_RV_REF_BEG boost::csbl::unique_ptr<int> BOOST_THREAD_RV_REF_END p
146 )
147 {
148   boost::this_thread::sleep_for(ms(200));
149   return boost::move(p);
150 }
151
152 struct check_timer {
153   boost::chrono::nanoseconds delay;
154   Clock::time_point start;
155   check_timer(boost::chrono::nanoseconds delay)
156   : delay(delay)
157   , start(Clock::now())
158   {
159   }
160   ~check_timer() {
161     Clock::time_point now = Clock::now();
162     BOOST_TEST(now - start < delay);
163     std::cout << __FILE__ << "[" << __LINE__ << "] " << (now - start).count() << std::endl;
164   }
165
166 };
167
168 int main()
169 {
170   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
171   {
172     try
173     {
174       boost::future<int> f = boost::async(f0);
175       boost::this_thread::sleep_for(ms(300));
176       int res;
177       {
178         check_timer timer(ms(500));
179         res = f.get();
180       }
181       BOOST_TEST(res == 3);
182     }
183     catch (std::exception& ex)
184     {
185       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
186       BOOST_TEST(false && "exception thrown");
187     }
188     catch (...)
189     {
190       BOOST_TEST(false && "exception thrown");
191     }
192
193   }
194   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
195   {
196     try
197     {
198       boost::shared_future<int> f = boost::async(f0).share();
199       boost::this_thread::sleep_for(ms(300));
200       int res;
201       {
202         check_timer timer(ms(500));
203         res = f.get();
204       }
205       BOOST_TEST(res == 3);
206     }
207     catch (std::exception& ex)
208     {
209       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
210       BOOST_TEST(false && "exception thrown");
211     }
212     catch (...)
213     {
214       BOOST_TEST(false && "exception thrown");
215     }
216
217   }
218   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
219   {
220     try
221     {
222       boost::future<int> f = boost::async(boost::launch::async, f0);
223       boost::this_thread::sleep_for(ms(300));
224       int res;
225       {
226         check_timer timer(ms(500));
227         res = f.get();
228       }
229       BOOST_TEST(res == 3);
230     }
231     catch (std::exception& ex)
232     {
233       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
234       BOOST_TEST(false && "exception thrown");
235     }
236     catch (...)
237     {
238       BOOST_TEST(false && "exception thrown");
239     }
240
241   }
242   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
243   {
244     try
245     {
246       boost::future<long> f = boost::async(boost::launch::async, A(3));
247       boost::this_thread::sleep_for(ms(300));
248       int res;
249       {
250         check_timer timer(ms(500));
251         res = f.get();
252       }
253       BOOST_TEST(res == 3);
254     }
255     catch (std::exception& ex)
256     {
257       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
258       BOOST_TEST(false && "exception thrown");
259     }
260     catch (...)
261     {
262       BOOST_TEST(false && "exception thrown");
263     }
264
265   }
266 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
267   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
268   {
269     try
270     {
271       boost::future<long> f = boost::async(boost::launch::deferred, A(3));
272       //boost::this_thread::sleep_for(ms(300));
273       int res;
274       {
275         check_timer timer(ms(500));
276         res = f.get();
277       }
278       BOOST_TEST(res == 3);
279     }
280     catch (std::exception& ex)
281     {
282       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
283       BOOST_TEST(false && "exception thrown");
284     }
285     catch (...)
286     {
287       BOOST_TEST(false && "exception thrown");
288     }
289
290   }
291 #endif
292 #if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
293   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
294   {
295     try
296     {
297       A a(3);
298       boost::future<long> f = boost::async(boost::launch::async, &A::doit, &a);
299       boost::this_thread::sleep_for(ms(300));
300       int res;
301       {
302         check_timer timer(ms(500));
303         res = f.get();
304       }
305       BOOST_TEST(res == 3);
306     }
307     catch (std::exception& ex)
308     {
309       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
310       BOOST_TEST(false && "exception thrown");
311     }
312     catch (...)
313     {
314       BOOST_TEST(false && "exception thrown");
315     }
316
317   }
318   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
319   {
320     try
321     {
322       A a(3);
323       boost::future<long> f = boost::async(boost::launch::deferred, &A::doit, &a);
324       boost::this_thread::sleep_for(ms(300));
325       int res;
326       {
327         check_timer timer(ms(500));
328         res = f.get();
329       }
330       BOOST_TEST(res == 3);
331     }
332     catch (std::exception& ex)
333     {
334       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
335       BOOST_TEST(false && "exception thrown");
336     }
337     catch (...)
338     {
339       BOOST_TEST(false && "exception thrown");
340     }
341
342   }
343 #endif
344   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
345   {
346     try
347     {
348       boost::future<int> f = boost::async(boost::launch::async, BOOST_THREAD_MAKE_RV_REF(MoveOnly()));
349       boost::this_thread::sleep_for(ms(300));
350       int res;
351       {
352         check_timer timer(ms(500));
353         res = f.get();
354       }
355       BOOST_TEST(res == 3);
356     }
357     catch (std::exception& ex)
358     {
359       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
360       BOOST_TEST(false && "exception thrown");
361     }
362     catch (...)
363     {
364       BOOST_TEST(false && "exception thrown");
365     }
366   }
367 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
368   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
369   {
370     try
371     {
372       boost::future<int> f = boost::async(boost::launch::deferred, BOOST_THREAD_MAKE_RV_REF(MoveOnly()));
373       boost::this_thread::sleep_for(ms(300));
374       int res;
375       {
376         check_timer timer(ms(500));
377         res = f.get();
378       }
379       BOOST_TEST(res == 3);
380     }
381     catch (std::exception& ex)
382     {
383       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
384       BOOST_TEST(false && "exception thrown");
385     }
386     catch (...)
387     {
388       BOOST_TEST(false && "exception thrown");
389     }
390   }
391 #endif
392   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
393   {
394     try
395     {
396       boost::future<int> f = boost::async(boost::launch::any, f0);
397       boost::this_thread::sleep_for(ms(300));
398       int res;
399       {
400         check_timer timer(ms(500));
401         res = f.get();
402       }
403       BOOST_TEST(res == 3);
404     }
405     catch (std::exception& ex)
406     {
407       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
408       BOOST_TEST(false && "exception thrown");
409     }
410     catch (...)
411     {
412       BOOST_TEST(false && "exception thrown");
413     }
414   }
415 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
416   std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
417   {
418     try
419     {
420       boost::future<int> f = boost::async(boost::launch::deferred, f0);
421       //boost::this_thread::sleep_for(ms(300));
422       int res;
423       {
424         check_timer timer(ms(500));
425         res = f.get();
426       }
427       BOOST_TEST(res == 3);
428     }
429     catch (std::exception& ex)
430     {
431       std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
432       BOOST_TEST(false && "exception thrown");
433     }
434     catch (...)
435     {
436       BOOST_TEST(false && "exception thrown");
437     }
438   }
439 #endif
440   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
441   {
442     try
443     {
444       boost::future<int&> f = boost::async(f1);
445       boost::this_thread::sleep_for(ms(300));
446       int* res;
447       {
448         check_timer timer(ms(500));
449         res = &f.get();
450       }
451       BOOST_TEST(res == &i);
452     }
453     catch (std::exception& ex)
454     {
455       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
456       BOOST_TEST(false && "exception thrown");
457     }
458     catch (...)
459     {
460       BOOST_TEST(false && "exception thrown");
461     }
462   }
463   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
464   {
465     try
466     {
467       boost::future<int&> f = boost::async(boost::launch::async, f1);
468       boost::this_thread::sleep_for(ms(300));
469       int* res;
470       {
471         check_timer timer(ms(500));
472         res = &f.get();
473       }
474       BOOST_TEST(res == &i);
475     }
476     catch (std::exception& ex)
477     {
478       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
479       BOOST_TEST(false && "exception thrown");
480     }
481     catch (...)
482     {
483       BOOST_TEST(false && "exception thrown");
484     }
485   }
486   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
487   {
488     try
489     {
490       boost::future<int&> f = boost::async(boost::launch::any, f1);
491       boost::this_thread::sleep_for(ms(300));
492       int* res;
493       {
494         check_timer timer(ms(500));
495         res = &f.get();
496       }
497       BOOST_TEST(res == &i);
498     }
499     catch (std::exception& ex)
500     {
501       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
502       BOOST_TEST(false && "exception thrown");
503     }
504     catch (...)
505     {
506       BOOST_TEST(false && "exception thrown");
507     }
508   }
509 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
510   std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
511   {
512     try
513     {
514       boost::future<int&> f = boost::async(boost::launch::deferred, f1);
515       //boost::this_thread::sleep_for(ms(300));
516       int* res;
517       {
518         check_timer timer(ms(500));
519         res = &f.get();
520       }
521       BOOST_TEST(res == &i);
522     }
523     catch (std::exception& ex)
524     {
525       std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
526       BOOST_TEST(false && "exception thrown");
527     }
528     catch (...)
529     {
530       BOOST_TEST(false && "exception thrown");
531     }
532   }
533 #endif
534   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
535   {
536     try
537     {
538       boost::future<void> f = boost::async(f2);
539       boost::this_thread::sleep_for(ms(300));
540       {
541         check_timer timer(ms(500));
542         f.get();
543       }
544     }
545     catch (std::exception& ex)
546     {
547       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
548       BOOST_TEST(false && "exception thrown");
549     }
550     catch (...)
551     {
552       BOOST_TEST(false && "exception thrown");
553     }
554   }
555   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
556   {
557     try
558     {
559       boost::future<void> f = boost::async(boost::launch::async, f2);
560       boost::this_thread::sleep_for(ms(300));
561       {
562         check_timer timer(ms(500));
563         f.get();
564       }
565     }
566     catch (std::exception& ex)
567     {
568       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
569       BOOST_TEST(false && "exception thrown");
570     }
571     catch (...)
572     {
573       BOOST_TEST(false && "exception thrown");
574     }
575   }
576   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
577   {
578     try
579     {
580       boost::future<void> f = boost::async(boost::launch::any, f2);
581       boost::this_thread::sleep_for(ms(300));
582       {
583         check_timer timer(ms(500));
584         f.get();
585       }
586     }
587     catch (std::exception& ex)
588     {
589       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
590       BOOST_TEST(false && "exception thrown");
591     }
592     catch (...)
593     {
594       BOOST_TEST(false && "exception thrown");
595     }
596   }
597 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
598   std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
599   {
600     try
601     {
602       boost::future<void> f = boost::async(boost::launch::deferred, f2);
603       //boost::this_thread::sleep_for(ms(300));
604       {
605         check_timer timer(ms(500));
606         f.get();
607       }
608     }
609     catch (std::exception& ex)
610     {
611       std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
612       BOOST_TEST(false && "exception thrown");
613     }
614     catch (...)
615     {
616       BOOST_TEST(false && "exception thrown");
617     }
618   }
619 #endif
620
621   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
622   {
623     try
624     {
625       boost::future<MoveOnly> f = boost::async(&f3_1);
626       boost::this_thread::sleep_for(ms(300));
627       MoveOnly res;
628       {
629         check_timer timer(ms(500));
630         res = f.get();
631       }
632       BOOST_TEST_EQ(res.value, 2);
633     }
634     catch (std::exception& ex)
635     {
636       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
637       BOOST_TEST(false && "exception thrown");
638     }
639     catch (...)
640     {
641       BOOST_TEST(false && "exception thrown");
642     }
643   }
644 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
645   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
646   {
647     try
648     {
649       boost::future<MoveOnly> f = boost::async(boost::launch::deferred, &f3_1);
650       //boost::this_thread::sleep_for(ms(300));
651       MoveOnly res;
652       {
653         check_timer timer(ms(500));
654         res = f.get();
655       }
656       BOOST_TEST_EQ(res.value, 2);
657     }
658     catch (std::exception& ex)
659     {
660       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
661       BOOST_TEST(false && "exception thrown");
662     }
663     catch (...)
664     {
665       BOOST_TEST(false && "exception thrown");
666     }
667   }
668 #endif
669   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
670   {
671     try
672     {
673       boost::future<MoveOnly> f;
674       f = boost::async(&f3_1);
675       boost::this_thread::sleep_for(ms(300));
676       MoveOnly res;
677       {
678         check_timer timer(ms(500));
679         res = f.get();
680       }
681       BOOST_TEST(res.value == 2);
682     }
683     catch (std::exception& ex)
684     {
685       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
686       BOOST_TEST(false && "exception thrown");
687     }
688     catch (...)
689     {
690       BOOST_TEST(false && "exception thrown");
691     }
692   }
693   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
694   {
695     try
696     {
697       boost::future<boost::csbl::unique_ptr<int> > f = boost::async(&f3_0);
698       boost::this_thread::sleep_for(ms(300));
699       boost::csbl::unique_ptr<int> res;
700       {
701         check_timer timer(ms(500));
702         res = f.get();
703       }
704       BOOST_TEST(*res == 3);
705     }
706     catch (std::exception& ex)
707     {
708       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
709       BOOST_TEST(false && "exception thrown");
710     }
711     catch (...)
712     {
713       BOOST_TEST(false && "exception thrown");
714     }
715   }
716
717 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
718   std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
719   {
720     try
721     {
722       boost::future<boost::csbl::unique_ptr<int> > f = boost::async(boost::launch::async, &f3, 3);
723       boost::this_thread::sleep_for(ms(300));
724       boost::csbl::unique_ptr<int> res;
725       {
726         check_timer timer(ms(500));
727         res = f.get();
728       }
729       BOOST_TEST(*res == 3);
730     }
731     catch (std::exception& ex)
732     {
733       std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
734       BOOST_TEST(false && "exception thrown");
735     }
736     catch (...)
737     {
738       BOOST_TEST(false && "exception thrown");
739     }
740   }
741   std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
742   {
743     try
744     {
745       boost::future<boost::csbl::unique_ptr<int> > f = boost::async(boost::launch::deferred, &f3, 3);
746       //boost::this_thread::sleep_for(ms(300));
747       boost::csbl::unique_ptr<int> res;
748       {
749         check_timer timer(ms(500));
750         res = f.get();
751       }
752       BOOST_TEST(*res == 3);
753     }
754     catch (std::exception& ex)
755     {
756       std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
757       BOOST_TEST(false && "exception thrown");
758     }
759     catch (...)
760     {
761       BOOST_TEST(false && "exception thrown");
762     }
763   }
764   std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
765   {
766     try
767     {
768       boost::future<boost::csbl::unique_ptr<int> > f = boost::async(&f3, 3);
769       boost::this_thread::sleep_for(ms(300));
770       boost::csbl::unique_ptr<int> res;
771       {
772         check_timer timer(ms(500));
773         res = f.get();
774       }
775       BOOST_TEST(*res == 3);
776     }
777     catch (std::exception& ex)
778     {
779       std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
780       BOOST_TEST(false && "exception thrown");
781     }
782     catch (...)
783     {
784       BOOST_TEST(false && "exception thrown");
785     }
786   }
787 #endif
788
789 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
790   std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
791   {
792     try
793     {
794       boost::future<boost::csbl::unique_ptr<int> > f = boost::async(boost::launch::async, &f4, boost::csbl::unique_ptr<int>(new int(3)));
795       boost::this_thread::sleep_for(ms(300));
796       boost::csbl::unique_ptr<int> res;
797       {
798         check_timer timer(ms(500));
799         res = f.get();
800       }
801       BOOST_TEST(*res == 3);
802     }
803     catch (std::exception& ex)
804     {
805       std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
806       BOOST_TEST(false && "exception thrown");
807     }
808     catch (...)
809     {
810       BOOST_TEST(false && "exception thrown");
811     }
812   }
813   std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
814   {
815     try
816     {
817       boost::future<boost::csbl::unique_ptr<int> > f = boost::async(boost::launch::deferred, &f4, boost::csbl::unique_ptr<int>(new int(3)));
818       //boost::this_thread::sleep_for(ms(300));
819       boost::csbl::unique_ptr<int> res;
820       {
821         check_timer timer(ms(500));
822         res = f.get();
823       }
824       BOOST_TEST(*res == 3);
825     }
826     catch (std::exception& ex)
827     {
828       std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
829       BOOST_TEST(false && "exception thrown");
830     }
831     catch (...)
832     {
833       BOOST_TEST(false && "exception thrown");
834     }
835   }
836   std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
837   {
838     try
839     {
840       boost::future<boost::csbl::unique_ptr<int> > f = boost::async(&f4, boost::csbl::unique_ptr<int>(new int(3)));
841       boost::this_thread::sleep_for(ms(300));
842       boost::csbl::unique_ptr<int> res;
843       {
844         check_timer timer(ms(500));
845         res = f.get();
846       }
847       BOOST_TEST(*res == 3);
848     }
849     catch (std::exception& ex)
850     {
851       std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
852       BOOST_TEST(false && "exception thrown");
853     }
854     catch (...)
855     {
856       BOOST_TEST(false && "exception thrown");
857     }
858   }
859 #endif
860   return boost::report_errors();
861 }