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 
A(long i)49   explicit A(long i) :
50     data_(i)
51   {
52   }
53 
doit() const54   long doit() const
55   {
56     boost::this_thread::sleep_for(ms(200));
57     return data_;
58   }
operator ()() const59   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)
MoveOnly()74   MoveOnly()
75   {
76     value = 0;
77   }
MoveOnly(BOOST_THREAD_RV_REF (MoveOnly))78   MoveOnly( BOOST_THREAD_RV_REF(MoveOnly))
79   {
80     value = 1;
81   }
operator =(BOOST_THREAD_RV_REF (MoveOnly))82   MoveOnly& operator=(BOOST_THREAD_RV_REF(MoveOnly))
83   {
84     value = 2;
85     return *this;
86   }
87 
operator ()() const88   int operator()() const
89   {
90     boost::this_thread::sleep_for(ms(200));
91     return 3;
92   }
93   template <typename OS>
operator <<(OS & os,MoveOnly const & v)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 
f0()106 int f0()
107 {
108   boost::this_thread::sleep_for(ms(200));
109   return 3;
110 }
111 
112 int i = 0;
113 
f1()114 int& f1()
115 {
116   boost::this_thread::sleep_for(ms(200));
117   return i;
118 }
119 
f2()120 void f2()
121 {
122   boost::this_thread::sleep_for(ms(200));
123 }
124 
f3_0()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 }
f3_1()131 MoveOnly f3_1()
132 {
133   boost::this_thread::sleep_for(ms(200));
134   MoveOnly r;
135   return boost::move(r);
136 }
137 
f3(int i)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 
f4(BOOST_THREAD_RV_REF_BEG boost::csbl::unique_ptr<int> BOOST_THREAD_RV_REF_END p)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;
check_timercheck_timer155   check_timer(boost::chrono::nanoseconds delay)
156   : delay(delay)
157   , start(Clock::now())
158   {
159   }
~check_timercheck_timer160   ~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 
main()168 int main()
169 {
170   {
171     try {
172       boost::async(f0);
173     } catch (std::exception& ex)
174     {
175       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
176       BOOST_TEST(false && "exception thrown");
177     }
178     catch (...)
179     {
180       BOOST_TEST(false && "exception thrown");
181     }
182   }
183   {
184     try {
185       boost::async(boost::launch::async, f0);
186     } catch (std::exception& ex)
187     {
188       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
189       BOOST_TEST(false && "exception thrown");
190     }
191     catch (...)
192     {
193       BOOST_TEST(false && "exception thrown");
194     }
195   }
196 #if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
197   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
198   {
199     try {
200       boost::async(boost::launch::deferred, f0);
201     } catch (std::exception& ex)
202     {
203       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
204       BOOST_TEST(false && "exception thrown");
205     }
206     catch (...)
207     {
208       BOOST_TEST(false && "exception thrown");
209     }
210   }
211 #endif
212   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
213   {
214     try
215     {
216       boost::future<int> f = boost::async(f0);
217       boost::this_thread::sleep_for(ms(300));
218       int res;
219       {
220         check_timer timer(ms(500));
221         res = f.get();
222       }
223       BOOST_TEST(res == 3);
224     }
225     catch (std::exception& ex)
226     {
227       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
228       BOOST_TEST(false && "exception thrown");
229     }
230     catch (...)
231     {
232       BOOST_TEST(false && "exception thrown");
233     }
234 
235   }
236   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
237   {
238     try
239     {
240       boost::shared_future<int> f = boost::async(f0).share();
241       boost::this_thread::sleep_for(ms(300));
242       int res;
243       {
244         check_timer timer(ms(500));
245         res = f.get();
246       }
247       BOOST_TEST(res == 3);
248     }
249     catch (std::exception& ex)
250     {
251       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
252       BOOST_TEST(false && "exception thrown");
253     }
254     catch (...)
255     {
256       BOOST_TEST(false && "exception thrown");
257     }
258 
259   }
260   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
261   {
262     try
263     {
264       boost::future<int> f = boost::async(boost::launch::async, f0);
265       boost::this_thread::sleep_for(ms(300));
266       int res;
267       {
268         check_timer timer(ms(500));
269         res = f.get();
270       }
271       BOOST_TEST(res == 3);
272     }
273     catch (std::exception& ex)
274     {
275       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
276       BOOST_TEST(false && "exception thrown");
277     }
278     catch (...)
279     {
280       BOOST_TEST(false && "exception thrown");
281     }
282 
283   }
284   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
285   {
286     try
287     {
288       boost::future<long> f = boost::async(boost::launch::async, A(3));
289       boost::this_thread::sleep_for(ms(300));
290       int res;
291       {
292         check_timer timer(ms(500));
293         res = f.get();
294       }
295       BOOST_TEST(res == 3);
296     }
297     catch (std::exception& ex)
298     {
299       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
300       BOOST_TEST(false && "exception thrown");
301     }
302     catch (...)
303     {
304       BOOST_TEST(false && "exception thrown");
305     }
306 
307   }
308 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
309   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
310   {
311     try
312     {
313       boost::future<long> f = boost::async(boost::launch::deferred, A(3));
314       //boost::this_thread::sleep_for(ms(300));
315       int res;
316       {
317         check_timer timer(ms(500));
318         res = f.get();
319       }
320       BOOST_TEST(res == 3);
321     }
322     catch (std::exception& ex)
323     {
324       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
325       BOOST_TEST(false && "exception thrown");
326     }
327     catch (...)
328     {
329       BOOST_TEST(false && "exception thrown");
330     }
331 
332   }
333 #endif
334 #if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
335   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
336   {
337     try
338     {
339       A a(3);
340       boost::future<long> f = boost::async(boost::launch::async, &A::doit, &a);
341       boost::this_thread::sleep_for(ms(300));
342       int res;
343       {
344         check_timer timer(ms(500));
345         res = f.get();
346       }
347       BOOST_TEST(res == 3);
348     }
349     catch (std::exception& ex)
350     {
351       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
352       BOOST_TEST(false && "exception thrown");
353     }
354     catch (...)
355     {
356       BOOST_TEST(false && "exception thrown");
357     }
358 
359   }
360   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
361   {
362     try
363     {
364       A a(3);
365       boost::future<long> f = boost::async(boost::launch::deferred, &A::doit, &a);
366       boost::this_thread::sleep_for(ms(300));
367       int res;
368       {
369         check_timer timer(ms(500));
370         res = f.get();
371       }
372       BOOST_TEST(res == 3);
373     }
374     catch (std::exception& ex)
375     {
376       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
377       BOOST_TEST(false && "exception thrown");
378     }
379     catch (...)
380     {
381       BOOST_TEST(false && "exception thrown");
382     }
383 
384   }
385 #endif
386   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
387   {
388     try
389     {
390       boost::future<int> f = boost::async(boost::launch::async, BOOST_THREAD_MAKE_RV_REF(MoveOnly()));
391       boost::this_thread::sleep_for(ms(300));
392       int res;
393       {
394         check_timer timer(ms(500));
395         res = f.get();
396       }
397       BOOST_TEST(res == 3);
398     }
399     catch (std::exception& ex)
400     {
401       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
402       BOOST_TEST(false && "exception thrown");
403     }
404     catch (...)
405     {
406       BOOST_TEST(false && "exception thrown");
407     }
408   }
409 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
410   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
411   {
412     try
413     {
414       boost::future<int> f = boost::async(boost::launch::deferred, BOOST_THREAD_MAKE_RV_REF(MoveOnly()));
415       boost::this_thread::sleep_for(ms(300));
416       int res;
417       {
418         check_timer timer(ms(500));
419         res = f.get();
420       }
421       BOOST_TEST(res == 3);
422     }
423     catch (std::exception& ex)
424     {
425       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
426       BOOST_TEST(false && "exception thrown");
427     }
428     catch (...)
429     {
430       BOOST_TEST(false && "exception thrown");
431     }
432   }
433 #endif
434   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
435   {
436     try
437     {
438       boost::future<int> f = boost::async(boost::launch::any, f0);
439       boost::this_thread::sleep_for(ms(300));
440       int res;
441       {
442         check_timer timer(ms(500));
443         res = f.get();
444       }
445       BOOST_TEST(res == 3);
446     }
447     catch (std::exception& ex)
448     {
449       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
450       BOOST_TEST(false && "exception thrown");
451     }
452     catch (...)
453     {
454       BOOST_TEST(false && "exception thrown");
455     }
456   }
457 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
458   std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
459   {
460     try
461     {
462       boost::future<int> f = boost::async(boost::launch::deferred, f0);
463       //boost::this_thread::sleep_for(ms(300));
464       int res;
465       {
466         check_timer timer(ms(500));
467         res = f.get();
468       }
469       BOOST_TEST(res == 3);
470     }
471     catch (std::exception& ex)
472     {
473       std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
474       BOOST_TEST(false && "exception thrown");
475     }
476     catch (...)
477     {
478       BOOST_TEST(false && "exception thrown");
479     }
480   }
481 #endif
482   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
483   {
484     try
485     {
486       boost::future<int&> f = boost::async(f1);
487       boost::this_thread::sleep_for(ms(300));
488       int* res;
489       {
490         check_timer timer(ms(500));
491         res = &f.get();
492       }
493       BOOST_TEST(res == &i);
494     }
495     catch (std::exception& ex)
496     {
497       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
498       BOOST_TEST(false && "exception thrown");
499     }
500     catch (...)
501     {
502       BOOST_TEST(false && "exception thrown");
503     }
504   }
505   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
506   {
507     try
508     {
509       boost::future<int&> f = boost::async(boost::launch::async, f1);
510       boost::this_thread::sleep_for(ms(300));
511       int* res;
512       {
513         check_timer timer(ms(500));
514         res = &f.get();
515       }
516       BOOST_TEST(res == &i);
517     }
518     catch (std::exception& ex)
519     {
520       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
521       BOOST_TEST(false && "exception thrown");
522     }
523     catch (...)
524     {
525       BOOST_TEST(false && "exception thrown");
526     }
527   }
528   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
529   {
530     try
531     {
532       boost::future<int&> f = boost::async(boost::launch::any, f1);
533       boost::this_thread::sleep_for(ms(300));
534       int* res;
535       {
536         check_timer timer(ms(500));
537         res = &f.get();
538       }
539       BOOST_TEST(res == &i);
540     }
541     catch (std::exception& ex)
542     {
543       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
544       BOOST_TEST(false && "exception thrown");
545     }
546     catch (...)
547     {
548       BOOST_TEST(false && "exception thrown");
549     }
550   }
551 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
552   std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
553   {
554     try
555     {
556       boost::future<int&> f = boost::async(boost::launch::deferred, f1);
557       //boost::this_thread::sleep_for(ms(300));
558       int* res;
559       {
560         check_timer timer(ms(500));
561         res = &f.get();
562       }
563       BOOST_TEST(res == &i);
564     }
565     catch (std::exception& ex)
566     {
567       std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
568       BOOST_TEST(false && "exception thrown");
569     }
570     catch (...)
571     {
572       BOOST_TEST(false && "exception thrown");
573     }
574   }
575 #endif
576   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
577   {
578     try
579     {
580       boost::future<void> f = boost::async(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   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
598   {
599     try
600     {
601       boost::future<void> f = boost::async(boost::launch::async, f2);
602       boost::this_thread::sleep_for(ms(300));
603       {
604         check_timer timer(ms(500));
605         f.get();
606       }
607     }
608     catch (std::exception& ex)
609     {
610       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
611       BOOST_TEST(false && "exception thrown");
612     }
613     catch (...)
614     {
615       BOOST_TEST(false && "exception thrown");
616     }
617   }
618   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
619   {
620     try
621     {
622       boost::future<void> f = boost::async(boost::launch::any, f2);
623       boost::this_thread::sleep_for(ms(300));
624       {
625         check_timer timer(ms(500));
626         f.get();
627       }
628     }
629     catch (std::exception& ex)
630     {
631       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
632       BOOST_TEST(false && "exception thrown");
633     }
634     catch (...)
635     {
636       BOOST_TEST(false && "exception thrown");
637     }
638   }
639 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
640   std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
641   {
642     try
643     {
644       boost::future<void> f = boost::async(boost::launch::deferred, f2);
645       //boost::this_thread::sleep_for(ms(300));
646       {
647         check_timer timer(ms(500));
648         f.get();
649       }
650     }
651     catch (std::exception& ex)
652     {
653       std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
654       BOOST_TEST(false && "exception thrown");
655     }
656     catch (...)
657     {
658       BOOST_TEST(false && "exception thrown");
659     }
660   }
661 #endif
662 
663   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
664   {
665     try
666     {
667       boost::future<MoveOnly> f = boost::async(&f3_1);
668       boost::this_thread::sleep_for(ms(300));
669       MoveOnly res;
670       {
671         check_timer timer(ms(500));
672         res = f.get();
673       }
674       BOOST_TEST_EQ(res.value, 2);
675     }
676     catch (std::exception& ex)
677     {
678       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
679       BOOST_TEST(false && "exception thrown");
680     }
681     catch (...)
682     {
683       BOOST_TEST(false && "exception thrown");
684     }
685   }
686 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
687   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
688   {
689     try
690     {
691       boost::future<MoveOnly> f = boost::async(boost::launch::deferred, &f3_1);
692       //boost::this_thread::sleep_for(ms(300));
693       MoveOnly res;
694       {
695         check_timer timer(ms(500));
696         res = f.get();
697       }
698       BOOST_TEST_EQ(res.value, 2);
699     }
700     catch (std::exception& ex)
701     {
702       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
703       BOOST_TEST(false && "exception thrown");
704     }
705     catch (...)
706     {
707       BOOST_TEST(false && "exception thrown");
708     }
709   }
710 #endif
711   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
712   {
713     try
714     {
715       boost::future<MoveOnly> f;
716       f = boost::async(&f3_1);
717       boost::this_thread::sleep_for(ms(300));
718       MoveOnly res;
719       {
720         check_timer timer(ms(500));
721         res = f.get();
722       }
723       BOOST_TEST(res.value == 2);
724     }
725     catch (std::exception& ex)
726     {
727       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
728       BOOST_TEST(false && "exception thrown");
729     }
730     catch (...)
731     {
732       BOOST_TEST(false && "exception thrown");
733     }
734   }
735   std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
736   {
737     try
738     {
739       boost::future<boost::csbl::unique_ptr<int> > f = boost::async(&f3_0);
740       boost::this_thread::sleep_for(ms(300));
741       boost::csbl::unique_ptr<int> res;
742       {
743         check_timer timer(ms(500));
744         res = f.get();
745       }
746       BOOST_TEST(*res == 3);
747     }
748     catch (std::exception& ex)
749     {
750       std::cout << __FILE__ << "[" << __LINE__ << "]" << ex.what() << std::endl;
751       BOOST_TEST(false && "exception thrown");
752     }
753     catch (...)
754     {
755       BOOST_TEST(false && "exception thrown");
756     }
757   }
758 
759 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
760   std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
761   {
762     try
763     {
764       boost::future<boost::csbl::unique_ptr<int> > f = boost::async(boost::launch::async, &f3, 3);
765       boost::this_thread::sleep_for(ms(300));
766       boost::csbl::unique_ptr<int> res;
767       {
768         check_timer timer(ms(500));
769         res = f.get();
770       }
771       BOOST_TEST(*res == 3);
772     }
773     catch (std::exception& ex)
774     {
775       std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
776       BOOST_TEST(false && "exception thrown");
777     }
778     catch (...)
779     {
780       BOOST_TEST(false && "exception thrown");
781     }
782   }
783   std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
784   {
785     try
786     {
787       boost::future<boost::csbl::unique_ptr<int> > f = boost::async(boost::launch::deferred, &f3, 3);
788       //boost::this_thread::sleep_for(ms(300));
789       boost::csbl::unique_ptr<int> res;
790       {
791         check_timer timer(ms(500));
792         res = f.get();
793       }
794       BOOST_TEST(*res == 3);
795     }
796     catch (std::exception& ex)
797     {
798       std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
799       BOOST_TEST(false && "exception thrown");
800     }
801     catch (...)
802     {
803       BOOST_TEST(false && "exception thrown");
804     }
805   }
806   std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
807   {
808     try
809     {
810       boost::future<boost::csbl::unique_ptr<int> > f = boost::async(&f3, 3);
811       boost::this_thread::sleep_for(ms(300));
812       boost::csbl::unique_ptr<int> res;
813       {
814         check_timer timer(ms(500));
815         res = f.get();
816       }
817       BOOST_TEST(*res == 3);
818     }
819     catch (std::exception& ex)
820     {
821       std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
822       BOOST_TEST(false && "exception thrown");
823     }
824     catch (...)
825     {
826       BOOST_TEST(false && "exception thrown");
827     }
828   }
829 #endif
830 
831 #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
832   std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
833   {
834     try
835     {
836       boost::future<boost::csbl::unique_ptr<int> > f = boost::async(boost::launch::async, &f4, boost::csbl::unique_ptr<int>(new int(3)));
837       boost::this_thread::sleep_for(ms(300));
838       boost::csbl::unique_ptr<int> res;
839       {
840         check_timer timer(ms(500));
841         res = f.get();
842       }
843       BOOST_TEST(*res == 3);
844     }
845     catch (std::exception& ex)
846     {
847       std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
848       BOOST_TEST(false && "exception thrown");
849     }
850     catch (...)
851     {
852       BOOST_TEST(false && "exception thrown");
853     }
854   }
855   std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
856   {
857     try
858     {
859       boost::future<boost::csbl::unique_ptr<int> > f = boost::async(boost::launch::deferred, &f4, boost::csbl::unique_ptr<int>(new int(3)));
860       //boost::this_thread::sleep_for(ms(300));
861       boost::csbl::unique_ptr<int> res;
862       {
863         check_timer timer(ms(500));
864         res = f.get();
865       }
866       BOOST_TEST(*res == 3);
867     }
868     catch (std::exception& ex)
869     {
870       std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
871       BOOST_TEST(false && "exception thrown");
872     }
873     catch (...)
874     {
875       BOOST_TEST(false && "exception thrown");
876     }
877   }
878   std::cout << __FILE__ <<"["<<__LINE__<<"]"<<std::endl;
879   {
880     try
881     {
882       boost::future<boost::csbl::unique_ptr<int> > f = boost::async(&f4, boost::csbl::unique_ptr<int>(new int(3)));
883       boost::this_thread::sleep_for(ms(300));
884       boost::csbl::unique_ptr<int> res;
885       {
886         check_timer timer(ms(500));
887         res = f.get();
888       }
889       BOOST_TEST(*res == 3);
890     }
891     catch (std::exception& ex)
892     {
893       std::cout << __FILE__ <<"["<<__LINE__<<"]"<<ex.what() << std::endl;
894       BOOST_TEST(false && "exception thrown");
895     }
896     catch (...)
897     {
898       BOOST_TEST(false && "exception thrown");
899     }
900   }
901 #endif
902   return boost::report_errors();
903 }
904