]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | // Copyright (C) 2011 Vicente J. Botet Escriba | |
10 | // | |
11 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
12 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
13 | ||
14 | // <boost/thread/thread.hpp> | |
15 | ||
16 | // class thread | |
17 | ||
18 | // template <class Clousure> thread(Clousure f); | |
19 | ||
20 | #include <new> | |
21 | #include <cstdlib> | |
22 | #include <cassert> | |
23 | #include <boost/thread/thread_only.hpp> | |
24 | #include <boost/detail/lightweight_test.hpp> | |
25 | ||
26 | #if ! defined BOOST_NO_CXX11_LAMBDAS | |
27 | ||
28 | unsigned throw_one = 0xFFFF; | |
29 | ||
30 | #if defined _GLIBCXX_THROW | |
b32b8144 | 31 | void* operator new(std::size_t s) _GLIBCXX_THROW (std::bad_alloc) |
7c673cae | 32 | #elif defined BOOST_MSVC |
b32b8144 FG |
33 | void* operator new(std::size_t s) |
34 | #elif __cplusplus > 201402L | |
35 | void* operator new(std::size_t s) | |
7c673cae FG |
36 | #else |
37 | void* operator new(std::size_t s) throw (std::bad_alloc) | |
38 | #endif | |
39 | { | |
40 | if (throw_one == 0) throw std::bad_alloc(); | |
41 | --throw_one; | |
42 | return std::malloc(s); | |
43 | } | |
44 | ||
45 | #if defined BOOST_MSVC | |
b32b8144 | 46 | void operator delete(void* p) |
7c673cae | 47 | #else |
b32b8144 | 48 | void operator delete(void* p) BOOST_NOEXCEPT_OR_NOTHROW |
7c673cae FG |
49 | #endif |
50 | { | |
51 | std::free(p); | |
52 | } | |
53 | ||
54 | bool f_run = false; | |
55 | ||
56 | int main() | |
57 | { | |
58 | { | |
59 | f_run = false; | |
60 | boost::thread t( []() { f_run = true; } ); | |
61 | t.join(); | |
62 | BOOST_TEST(f_run == true); | |
63 | } | |
64 | #ifndef BOOST_MSVC | |
65 | { | |
66 | f_run = false; | |
67 | try | |
68 | { | |
69 | throw_one = 0; | |
70 | boost::thread t( []() { f_run = true; } ); | |
71 | BOOST_TEST(false); | |
72 | } | |
73 | catch (...) | |
74 | { | |
75 | throw_one = 0xFFFF; | |
76 | BOOST_TEST(!f_run); | |
77 | } | |
78 | } | |
79 | #endif | |
80 | ||
81 | return boost::report_errors(); | |
82 | } | |
83 | ||
84 | #else | |
85 | int main() | |
86 | { | |
87 | return 0; | |
88 | } | |
89 | #endif |