diff options
Diffstat (limited to 'src/boost/libs/thread/test/threads')
27 files changed, 2353 insertions, 0 deletions
diff --git a/src/boost/libs/thread/test/threads/container/thread_ptr_list_pass.cpp b/src/boost/libs/thread/test/threads/container/thread_ptr_list_pass.cpp new file mode 100644 index 00000000..76047051 --- /dev/null +++ b/src/boost/libs/thread/test/threads/container/thread_ptr_list_pass.cpp @@ -0,0 +1,101 @@ +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#define BOOST_THREAD_USES_MOVE + +#include <boost/config.hpp> +#include <boost/thread/thread.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/csbl/list.hpp> +//#include <boost/interprocess/smart_ptr/shared_ptr.hpp> +#include <boost/smart_ptr.hpp> +#include <iostream> +#include <boost/detail/lightweight_test.hpp> + + +int count = 0; +boost::mutex mutex; + +namespace { + + +template <typename TC> +void join_all(TC & tc) +{ + for (typename TC::iterator it = tc.begin(); it != tc.end(); ++it) + { + (*it)->join(); + } +} + + +void increment_count() +{ + boost::unique_lock<boost::mutex> lock(mutex); + std::cout << "count = " << ++count << std::endl; +} + +template <class T> +struct default_delete +{ + typedef T* pointer; + + BOOST_CONSTEXPR default_delete() BOOST_NOEXCEPT {} //= default; + template <class U> + default_delete(const default_delete<U>&) BOOST_NOEXCEPT + {} + void operator()(T* ptr) const + { + delete ptr; + } +}; + +} +int main() +{ + { + typedef boost::shared_ptr<boost::thread > thread_ptr; + //typedef boost::interprocess::shared_ptr<boost::thread, std::allocator<boost::thread>, default_delete<boost::thread> > thread_ptr; + typedef boost::csbl::list<thread_ptr > thread_ptr_list; + thread_ptr_list threads; + for (int i = 0; i < 10; ++i) + { + //threads.push_back(BOOST_THREAD_MAKE_RV_REF(thread_ptr(new boost::thread(&increment_count)))); + threads.push_back(thread_ptr(new boost::thread(&increment_count))); + } + BOOST_TEST(threads.size()==10); + //join_all(threads); + for (thread_ptr_list::iterator it = threads.begin(); it != threads.end(); ++it) + { + (*it)->join(); + } + } + count = 0; + { + typedef boost::shared_ptr<boost::thread > thread_ptr; + //typedef boost::interprocess::shared_ptr<boost::thread, std::allocator<boost::thread>, default_delete<boost::thread> > thread_ptr; + typedef boost::csbl::list<thread_ptr > thread_ptr_list; + thread_ptr_list threads; + for (int i = 0; i < 10; ++i) + { + //threads.push_back(BOOST_THREAD_MAKE_RV_REF(thread_ptr(new boost::thread(&increment_count)))); + threads.push_back(thread_ptr(new boost::thread(&increment_count))); + } + BOOST_TEST(threads.size()==10); + thread_ptr sth(new boost::thread(&increment_count)); + threads.push_back(sth); + BOOST_TEST(threads.size()==11); + threads.remove(sth); + BOOST_TEST(threads.size()==10); + sth->join(); + //join_all(threads); + for (thread_ptr_list::iterator it = threads.begin(); it != threads.end(); ++it) + { + (*it)->join(); + } + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/threads/container/thread_vector_pass.cpp b/src/boost/libs/thread/test/threads/container/thread_vector_pass.cpp new file mode 100644 index 00000000..059a77e3 --- /dev/null +++ b/src/boost/libs/thread/test/threads/container/thread_vector_pass.cpp @@ -0,0 +1,97 @@ +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#define BOOST_THREAD_USES_MOVE + +#include <boost/thread/thread.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/csbl/vector.hpp> +#include <iostream> +#include <boost/detail/lightweight_test.hpp> +#include <boost/static_assert.hpp> + +int count = 0; +boost::mutex mutex; + +namespace +{ +template <typename TC> +void join_all(TC & tc) +{ + for (typename TC::iterator it = tc.begin(); it != tc.end(); ++it) + { + it->join(); + } +} + +template <typename TC> +void interrupt_all(TC & tc) +{ +#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS + for (typename TC::iterator it = tc.begin(); it != tc.end(); ++it) + { + it->interrupt(); + } +#endif +} +} + +void increment_count() +{ + boost::unique_lock<boost::mutex> lock(mutex); + std::cout << "count = " << ++count << std::endl; +} + +#if defined BOOST_NO_CXX11_RVALUE_REFERENCES && defined BOOST_THREAD_USES_MOVE +BOOST_STATIC_ASSERT(::boost::is_function<boost::rv<boost::rv<boost::thread> >&>::value==false); +#endif + +int main() +{ + typedef boost::csbl::vector<boost::thread> thread_vector; + { + thread_vector threads; + threads.reserve(10); + for (int i = 0; i < 10; ++i) + { + boost::thread th(&increment_count); + threads.push_back(boost::move(th)); + } + join_all(threads); + } + count = 0; + { + thread_vector threads; + threads.reserve(10); + for (int i = 0; i < 10; ++i) + { + threads.push_back(BOOST_THREAD_MAKE_RV_REF(boost::thread(&increment_count))); + } + join_all(threads); + } + count = 0; + { + thread_vector threads; + threads.reserve(10); + for (int i = 0; i < 10; ++i) + { + threads.emplace_back(&increment_count); + } + join_all(threads); + } + count = 0; + { + thread_vector threads; + threads.reserve(10); + for (int i = 0; i < 10; ++i) + { + threads.emplace_back(&increment_count); + } + interrupt_all(threads); + join_all(threads); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/threads/this_thread/get_id/get_id_pass.cpp b/src/boost/libs/thread/test/threads/this_thread/get_id/get_id_pass.cpp new file mode 100644 index 00000000..f0287cb6 --- /dev/null +++ b/src/boost/libs/thread/test/threads/this_thread/get_id/get_id_pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/thread.hpp> + +// thread::id this_thread::get_id(); + +#include <boost/thread/thread_only.hpp> + +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::thread::id id = boost::this_thread::get_id(); + BOOST_TEST(id != boost::thread::id()); + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/threads/this_thread/sleep_for/sleep_for_pass.cpp b/src/boost/libs/thread/test/threads/this_thread/sleep_for/sleep_for_pass.cpp new file mode 100644 index 00000000..05c5a790 --- /dev/null +++ b/src/boost/libs/thread/test/threads/this_thread/sleep_for/sleep_for_pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/thread.hpp> + +// thread::id this_thread::get_id(); + +#include <boost/thread/thread_only.hpp> +#include <cstdlib> +#include <algorithm> + +#include <boost/detail/lightweight_test.hpp> + +#if defined BOOST_THREAD_USES_CHRONO + +int main() +{ + { + typedef boost::chrono::system_clock Clock; + typedef Clock::time_point time_point; + boost::chrono::milliseconds ms(500); + time_point t0 = Clock::now(); + boost::this_thread::sleep_for(ms); + time_point t1 = Clock::now(); + boost::chrono::nanoseconds ns = (t1 - t0) - ms; + boost::chrono::nanoseconds err = ms / 100; + // The time slept is within 1% of 500ms + // This test is spurious as it depends on the time the thread system switches the threads + BOOST_TEST((std::max)(ns.count(), -ns.count()) < (err+boost::chrono::milliseconds(1000)).count()); + //BOOST_TEST(std::abs(static_cast<long>(ns.count())) < (err+boost::chrono::milliseconds(1000)).count()); + } + { + typedef boost::chrono::system_clock Clock; + typedef Clock::time_point time_point; + boost::chrono::milliseconds ms(500); + time_point t0 = Clock::now(); + boost::this_thread::no_interruption_point::sleep_for(ms); + time_point t1 = Clock::now(); + boost::chrono::nanoseconds ns = (t1 - t0) - ms; + boost::chrono::nanoseconds err = ms / 100; + // The time slept is within 1% of 500ms + // This test is spurious as it depends on the time the thread system switches the threads + BOOST_TEST((std::max)(ns.count(), -ns.count()) < (err+boost::chrono::milliseconds(1000)).count()); + //BOOST_TEST(std::abs(static_cast<long>(ns.count())) < (err+boost::chrono::milliseconds(1000)).count()); + } + return boost::report_errors(); + +} + +#else +#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported" +#endif + diff --git a/src/boost/libs/thread/test/threads/this_thread/sleep_until/sleep_until_pass.cpp b/src/boost/libs/thread/test/threads/this_thread/sleep_until/sleep_until_pass.cpp new file mode 100644 index 00000000..232712ee --- /dev/null +++ b/src/boost/libs/thread/test/threads/this_thread/sleep_until/sleep_until_pass.cpp @@ -0,0 +1,95 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/thread.hpp> + +// thread::id this_thread::get_id(); + +#include <boost/thread/thread_only.hpp> +#include <cstdlib> +#include <algorithm> + +#include <boost/detail/lightweight_test.hpp> + +#if defined BOOST_THREAD_USES_CHRONO + +int main() +{ + { + typedef boost::chrono::steady_clock Clock; + typedef Clock::time_point time_point; + //typedef Clock::duration duration; + boost::chrono::milliseconds ms(500); + time_point t0 = Clock::now(); + boost::this_thread::sleep_until(t0 + ms); + time_point t1 = Clock::now(); + boost::chrono::nanoseconds ns = (t1 - t0) - ms; + boost::chrono::nanoseconds err = ms / 100; + // The time slept is within 1% of 500ms + // This test is spurious as it depends on the time the thread system switches the threads + BOOST_TEST((std::max)(ns.count(), -ns.count()) < (err+boost::chrono::milliseconds(1000)).count()); + //BOOST_TEST(std::abs(static_cast<long>(ns.count())) < (err+boost::chrono::milliseconds(1000)).count()); + } + { + typedef boost::chrono::system_clock Clock; + typedef Clock::time_point time_point; + //typedef Clock::duration duration; + boost::chrono::milliseconds ms(500); + time_point t0 = Clock::now(); + boost::this_thread::sleep_until(t0 + ms); + time_point t1 = Clock::now(); + boost::chrono::nanoseconds ns = (t1 - t0) - ms; + boost::chrono::nanoseconds err = ms / 100; + // The time slept is within 1% of 500ms + // This test is spurious as it depends on the time the thread system switches the threads + BOOST_TEST((std::max)(ns.count(), -ns.count()) < (err+boost::chrono::milliseconds(1000)).count()); + //BOOST_TEST(std::abs(static_cast<long>(ns.count())) < (err+boost::chrono::milliseconds(1000)).count()); + } + { + typedef boost::chrono::steady_clock Clock; + typedef Clock::time_point time_point; + //typedef Clock::duration duration; + boost::chrono::milliseconds ms(500); + time_point t0 = Clock::now(); + boost::this_thread::no_interruption_point::sleep_until(t0 + ms); + time_point t1 = Clock::now(); + boost::chrono::nanoseconds ns = (t1 - t0) - ms; + boost::chrono::nanoseconds err = ms / 100; + // The time slept is within 1% of 500ms + // This test is spurious as it depends on the time the thread system switches the threads + BOOST_TEST((std::max)(ns.count(), -ns.count()) < (err+boost::chrono::milliseconds(1000)).count()); + //BOOST_TEST(std::abs(static_cast<long>(ns.count())) < (err+boost::chrono::milliseconds(1000)).count()); + } + { + typedef boost::chrono::system_clock Clock; + typedef Clock::time_point time_point; + //typedef Clock::duration duration; + boost::chrono::milliseconds ms(500); + time_point t0 = Clock::now(); + boost::this_thread::no_interruption_point::sleep_until(t0 + ms); + time_point t1 = Clock::now(); + boost::chrono::nanoseconds ns = (t1 - t0) - ms; + boost::chrono::nanoseconds err = ms / 100; + // The time slept is within 1% of 500ms + // This test is spurious as it depends on the time the thread system switches the threads + BOOST_TEST((std::max)(ns.count(), -ns.count()) < (err+boost::chrono::milliseconds(1000)).count()); + //BOOST_TEST(std::abs(static_cast<long>(ns.count())) < (err+boost::chrono::milliseconds(1000)).count()); + } + return boost::report_errors(); + +} + +#else +#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported" +#endif + diff --git a/src/boost/libs/thread/test/threads/thread/assign/copy_fail.cpp b/src/boost/libs/thread/test/threads/thread/assign/copy_fail.cpp new file mode 100644 index 00000000..5ccac5b3 --- /dev/null +++ b/src/boost/libs/thread/test/threads/thread/assign/copy_fail.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/thread.hpp> + +// class thread + +// thread& operator=(thread&& t); + +#include <boost/thread/thread_only.hpp> +#include <new> +#include <cstdlib> +#include <boost/detail/lightweight_test.hpp> + +class G +{ + int alive_; +public: + static int n_alive; + static bool op_run; + + G() : + alive_(1) + { + ++n_alive; + } + G(const G& g) : + alive_(g.alive_) + { + ++n_alive; + } + ~G() + { + alive_ = 0; + --n_alive; + } + + void operator()() + { + BOOST_TEST(alive_ == 1); + //BOOST_TEST(n_alive == 1); + op_run = true; + } + +}; + +int G::n_alive = 0; +bool G::op_run = false; + +int main() +{ + { + boost::thread t0( (G())); + boost::thread t1; + t1 = t0; + } +} + +#include "../../../remove_error_code_unused_warning.hpp" diff --git a/src/boost/libs/thread/test/threads/thread/assign/move_pass.cpp b/src/boost/libs/thread/test/threads/thread/assign/move_pass.cpp new file mode 100644 index 00000000..293c5d83 --- /dev/null +++ b/src/boost/libs/thread/test/threads/thread/assign/move_pass.cpp @@ -0,0 +1,101 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/thread.hpp> + +// class thread + +// thread& operator=(thread&& t); + +#define BOOST_THREAD_PROVIDES_THREAD_MOVE_ASSIGN_CALLS_TERMINATE_IF_JOINABLE + +#include <boost/thread/thread_only.hpp> +#include <new> +#include <cstdlib> +#include <cassert> +#include <boost/detail/lightweight_test.hpp> + +class G +{ + int alive_; +public: + static int n_alive; + static bool op_run; + + G() : + alive_(1) + { + ++n_alive; + } + G(const G& g) : + alive_(g.alive_) + { + ++n_alive; + } + ~G() + { + alive_ = 0; + --n_alive; + } + + void operator()() + { + BOOST_TEST(alive_ == 1); + //BOOST_TEST(n_alive == 1); + op_run = true; + } + + void operator()(int i, double j) + { + BOOST_TEST(alive_ == 1); + //BOOST_TEST(n_alive == 1); + BOOST_TEST(i == 5); + BOOST_TEST(j == 5.5); + op_run = true; + } +}; + +int G::n_alive = 0; +bool G::op_run = false; + +void f1() +{ + std::exit(boost::report_errors()); +} + +int main() +{ + std::set_terminate(f1); + { + BOOST_TEST(G::n_alive == 0); + BOOST_TEST(!G::op_run); + boost::thread t0(G(), 5, 5.5); + boost::thread::id id = t0.get_id(); + boost::thread t1; + t1 = boost::move(t0); + BOOST_TEST(t1.get_id() == id); + BOOST_TEST(t0.get_id() == boost::thread::id()); + t1.join(); + BOOST_TEST(G::op_run); + } + BOOST_TEST(G::n_alive == 0); + { + boost::thread t0(G(), 5, 5.5); + boost::thread t1; + t0 = boost::move(t1); + BOOST_TEST(false); + } + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/threads/thread/constr/FArgs_pass.cpp b/src/boost/libs/thread/test/threads/thread/constr/FArgs_pass.cpp new file mode 100644 index 00000000..e12c5187 --- /dev/null +++ b/src/boost/libs/thread/test/threads/thread/constr/FArgs_pass.cpp @@ -0,0 +1,145 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/thread.hpp> + +// class thread + +// template <class F, class ...Args> thread(F f, Args... args); + +#include <new> +#include <cstdlib> +#include <cassert> +#include <boost/thread/thread_only.hpp> +#include <boost/detail/lightweight_test.hpp> + +unsigned throw_one = 0xFFFF; + +#if defined _GLIBCXX_THROW +void* operator new(std::size_t s) _GLIBCXX_THROW (std::bad_alloc) +#elif defined BOOST_MSVC +void* operator new(std::size_t s) +#elif __cplusplus > 201402L +void* operator new(std::size_t s) +#else +void* operator new(std::size_t s) throw (std::bad_alloc) +#endif +{ + //std::cout << __FILE__ << ":" << __LINE__ << std::endl; + if (throw_one == 0) throw std::bad_alloc(); + --throw_one; + return std::malloc(s); +} + +#if defined BOOST_MSVC +void operator delete(void* p) +#else +void operator delete(void* p) BOOST_NOEXCEPT_OR_NOTHROW +#endif +{ + //std::cout << __FILE__ << ":" << __LINE__ << std::endl; + std::free(p); +} + +bool f_run = false; + +void f(int i, double j) +{ + BOOST_TEST(i == 5); + BOOST_TEST(j == 5.5); + f_run = true; +} + +class G +{ + int alive_; +public: + static int n_alive; + static bool op_run; + + G() : + alive_(1) + { + ++n_alive; + } + G(const G& g) : + alive_(g.alive_) + { + ++n_alive; + } + ~G() + { + alive_ = 0; + --n_alive; + } + + void operator()(int i, double j) + { + BOOST_TEST(alive_ == 1); + //BOOST_TEST(n_alive >= 1); + BOOST_TEST(i == 5); + BOOST_TEST(j == 5.5); + op_run = true; + } +}; + +int G::n_alive = 0; +bool G::op_run = false; + + +int main() +{ + { + std::cout << __FILE__ << ":" << __LINE__ <<" " << G::n_alive << std::endl; + boost::thread t(f, 5, 5.5); + t.join(); + BOOST_TEST(f_run == true); + std::cout << __FILE__ << ":" << __LINE__ <<" " << G::n_alive << std::endl; + } +#ifndef BOOST_MSVC + f_run = false; + { + std::cout << __FILE__ << ":" << __LINE__ <<" " << G::n_alive << std::endl; + try + { + std::cout << __FILE__ << ":" << __LINE__ <<" " << G::n_alive << std::endl; + throw_one = 0; + boost::thread t(f, 5, 5.5); + BOOST_TEST(false); + std::cout << __FILE__ << ":" << __LINE__ <<" " << G::n_alive << std::endl; + } + catch (...) + { + std::cout << __FILE__ << ":" << __LINE__ <<" " << G::n_alive << std::endl; + throw_one = 0xFFFF; + BOOST_TEST(!f_run); + std::cout << __FILE__ << ":" << __LINE__ <<" " << G::n_alive << std::endl; + } + std::cout << __FILE__ << ":" << __LINE__ <<" " << G::n_alive << std::endl; + } +#endif + { + std::cout << __FILE__ << ":" << __LINE__ <<" " << G::n_alive << std::endl; + BOOST_TEST(G::n_alive == 0); + std::cout << __FILE__ << ":" << __LINE__ <<" " << G::n_alive << std::endl; + BOOST_TEST(!G::op_run); + boost::thread t(G(), 5, 5.5); + t.join(); + std::cout << __FILE__ << ":" << __LINE__ <<" " << G::n_alive << std::endl; + BOOST_TEST(G::n_alive == 0); + BOOST_TEST(G::op_run); + std::cout << __FILE__ << ":" << __LINE__ <<" " << G::n_alive << std::endl; + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/threads/thread/constr/F_pass.cpp b/src/boost/libs/thread/test/threads/thread/constr/F_pass.cpp new file mode 100644 index 00000000..b99e90ba --- /dev/null +++ b/src/boost/libs/thread/test/threads/thread/constr/F_pass.cpp @@ -0,0 +1,150 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/thread.hpp> + +// class thread + +// template <class F, class ...Args> thread(F f, Args... args); + +#include <new> +#include <cstdlib> +#include <cassert> +#include <boost/thread/thread_only.hpp> +#include <boost/detail/lightweight_test.hpp> + +unsigned throw_one = 0xFFFF; + +#if defined _GLIBCXX_THROW +void* operator new(std::size_t s) _GLIBCXX_THROW (std::bad_alloc) +#elif defined BOOST_MSVC +void* operator new(std::size_t s) +#elif __cplusplus > 201402L +void* operator new(std::size_t s) +#else +void* operator new(std::size_t s) throw (std::bad_alloc) +#endif +{ + //std::cout << __FILE__ << ":" << __LINE__ << std::endl; + if (throw_one == 0) throw std::bad_alloc(); + --throw_one; + return std::malloc(s); +} + +#if defined BOOST_MSVC +void operator delete(void* p) +#else +void operator delete(void* p) BOOST_NOEXCEPT_OR_NOTHROW +#endif +{ + //std::cout << __FILE__ << ":" << __LINE__ << std::endl; + std::free(p); +} + +bool f_run = false; + +void f() +{ + f_run = true; +} + +class G +{ + int alive_; +public: + static int n_alive; + static bool op_run; + + G() : + alive_(1) + { + ++n_alive; + } + G(const G& g) : + alive_(g.alive_) + { + ++n_alive; + } + ~G() + { + alive_ = 0; + --n_alive; + } + + void operator()() + { + BOOST_TEST(alive_ == 1); + //BOOST_TEST(n_alive >= 1); + op_run = true; + } + +}; + +int G::n_alive = 0; +bool G::op_run = false; + + +int main() +{ + { + boost::thread t(f); + t.join(); + BOOST_TEST(f_run == true); + } + f_run = false; +#ifndef BOOST_MSVC + { + try + { + throw_one = 0; + boost::thread t(f); + BOOST_TEST(false); + } + catch (...) + { + throw_one = 0xFFFF; + BOOST_TEST(!f_run); + } + } +#endif + { + BOOST_TEST(G::n_alive == 0); + BOOST_TEST(!G::op_run); + boost::thread t( (G())); + t.join(); + BOOST_TEST(G::n_alive == 0); + BOOST_TEST(G::op_run); + } +#ifndef BOOST_MSVC + G::op_run = false; + { + try + { + throw_one = 0; + BOOST_TEST(G::n_alive == 0); + BOOST_TEST(!G::op_run); + boost::thread t( (G())); + BOOST_TEST(false); + } + catch (...) + { + throw_one = 0xFFFF; + BOOST_TEST(G::n_alive == 0); + std::cout << __FILE__ << ":" << __LINE__ <<" " << G::n_alive << std::endl; + BOOST_TEST(!G::op_run); + } + } +#endif + + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/threads/thread/constr/FrvalueArgs_pass.cpp b/src/boost/libs/thread/test/threads/thread/constr/FrvalueArgs_pass.cpp new file mode 100644 index 00000000..e76db702 --- /dev/null +++ b/src/boost/libs/thread/test/threads/thread/constr/FrvalueArgs_pass.cpp @@ -0,0 +1,103 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/thread.hpp> + +// class thread + +// template <class F, class ...Args> thread(F&& f, Args&&... args); + +#define BOOST_THREAD_VERSION 4 + +#include <boost/thread/thread_only.hpp> +#include <new> +#include <cstdlib> +#include <cassert> +#include <boost/detail/lightweight_test.hpp> + +class MoveOnly +{ +public: + BOOST_THREAD_MOVABLE_ONLY(MoveOnly) + MoveOnly() + { + } + MoveOnly(BOOST_THREAD_RV_REF(MoveOnly)) + {} + + void operator()(BOOST_THREAD_RV_REF(MoveOnly)) + { + } +}; + +class M +{ + +public: + long data_; + static int n_moves; + + BOOST_THREAD_MOVABLE_ONLY(M) + static void reset() { + n_moves=0; + } + explicit M(long i) : data_(i) + { + } + M(BOOST_THREAD_RV_REF(M) a) : data_(BOOST_THREAD_RV(a).data_) + { + BOOST_THREAD_RV(a).data_ = -1; + ++n_moves; + } + M& operator=(BOOST_THREAD_RV_REF(M) a) + { + data_ = BOOST_THREAD_RV(a).data_; + BOOST_THREAD_RV(a).data_ = -1; + ++n_moves; + return *this; + } + ~M() + { + } + + void operator()(int) const + { } + long operator()() const + { return data_;} + long operator()(long i, long j) const + { return data_ + i + j;} +}; + +int M::n_moves = 0; + +void fct(BOOST_THREAD_RV_REF(M) v) +{ + BOOST_TEST_EQ(v.data_, 1); +} + +int main() +{ +#if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD) + { + boost::thread t = boost::thread( MoveOnly(), MoveOnly() ); + t.join(); + } + { + M::reset(); + boost::thread t = boost::thread( fct, M(1) ); + t.join(); + BOOST_TEST_EQ(M::n_moves, 2); + } +#endif + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/threads/thread/constr/Frvalue_pass.cpp b/src/boost/libs/thread/test/threads/thread/constr/Frvalue_pass.cpp new file mode 100644 index 00000000..38061e0a --- /dev/null +++ b/src/boost/libs/thread/test/threads/thread/constr/Frvalue_pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/thread.hpp> + +// class thread + +// template <class F, class ...Args> thread(F&& f, Args&&... args); + +#define BOOST_THREAD_USES_MOVE + +#include <boost/thread/thread_only.hpp> +#include <new> +#include <cstdlib> +#include <cassert> +#include <boost/detail/lightweight_test.hpp> +#include <boost/static_assert.hpp> + +class MoveOnly +{ +public: + BOOST_THREAD_MOVABLE_ONLY(MoveOnly) + MoveOnly() + { + } + MoveOnly(BOOST_THREAD_RV_REF(MoveOnly)) + {} + + void operator()() + { + } +}; + +MoveOnly MakeMoveOnly() { + return BOOST_THREAD_MAKE_RV_REF(MoveOnly()); +} + +#if defined BOOST_NO_CXX11_RVALUE_REFERENCES && defined BOOST_THREAD_USES_MOVE +BOOST_STATIC_ASSERT(::boost::is_function<boost::rv<boost::rv<MoveOnly> >&>::value==false); +#endif + +int main() +{ + { + boost::thread t(( BOOST_THREAD_MAKE_RV_REF(MakeMoveOnly()) )); + t.join(); + } + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/threads/thread/constr/copy_fail.cpp b/src/boost/libs/thread/test/threads/thread/constr/copy_fail.cpp new file mode 100644 index 00000000..caa72c2d --- /dev/null +++ b/src/boost/libs/thread/test/threads/thread/constr/copy_fail.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/thread.hpp> + +// class thread + +// thread(const thread&) = delete; + +#include <boost/thread/thread_only.hpp> +#include <new> +#include <cstdlib> +#include <boost/detail/lightweight_test.hpp> + +class G +{ + int alive_; +public: + static int n_alive; + static bool op_run; + + G() : + alive_(1) + { + ++n_alive; + } + G(const G& g) : + alive_(g.alive_) + { + ++n_alive; + } + ~G() + { + alive_ = 0; + --n_alive; + } + + void operator()() + { + BOOST_TEST(alive_ == 1); + //BOOST_TEST(n_alive == 1); + op_run = true; + } + + void operator()(int i, double j) + { + BOOST_TEST(alive_ == 1); + //BOOST_TEST(n_alive == 1); + BOOST_TEST(i == 5); + BOOST_TEST(j == 5.5); + op_run = true; + } +}; + +int G::n_alive = 0; +bool G::op_run = false; + +int main() +{ + { + BOOST_TEST(G::n_alive == 0); + BOOST_TEST(!G::op_run); + boost::thread t0(G(), 5, 5.5); + boost::thread::id id = t0.get_id(); + boost::thread t1( (t0)); + BOOST_TEST(t1.get_id() == id); + BOOST_TEST(t0.get_id() == boost::thread::id()); + t1.join(); + BOOST_TEST(G::n_alive == 0); + BOOST_TEST(G::op_run); + } +} + +#include "../../../remove_error_code_unused_warning.hpp" + diff --git a/src/boost/libs/thread/test/threads/thread/constr/default_pass.cpp b/src/boost/libs/thread/test/threads/thread/constr/default_pass.cpp new file mode 100644 index 00000000..cea602d1 --- /dev/null +++ b/src/boost/libs/thread/test/threads/thread/constr/default_pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/thread.hpp> + +// class thread + +// thread(); + +#include <boost/thread/thread_only.hpp> +#include <cassert> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + boost::thread t; + BOOST_TEST(t.get_id() == boost::thread::id()); + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/threads/thread/constr/lambda_pass.cpp b/src/boost/libs/thread/test/threads/thread/constr/lambda_pass.cpp new file mode 100644 index 00000000..34a3e53c --- /dev/null +++ b/src/boost/libs/thread/test/threads/thread/constr/lambda_pass.cpp @@ -0,0 +1,89 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/thread.hpp> + +// class thread + +// template <class Clousure> thread(Clousure f); + +#include <new> +#include <cstdlib> +#include <cassert> +#include <boost/thread/thread_only.hpp> +#include <boost/detail/lightweight_test.hpp> + +#if ! defined BOOST_NO_CXX11_LAMBDAS + +unsigned throw_one = 0xFFFF; + +#if defined _GLIBCXX_THROW +void* operator new(std::size_t s) _GLIBCXX_THROW (std::bad_alloc) +#elif defined BOOST_MSVC +void* operator new(std::size_t s) +#elif __cplusplus > 201402L +void* operator new(std::size_t s) +#else +void* operator new(std::size_t s) throw (std::bad_alloc) +#endif +{ + if (throw_one == 0) throw std::bad_alloc(); + --throw_one; + return std::malloc(s); +} + +#if defined BOOST_MSVC +void operator delete(void* p) +#else +void operator delete(void* p) BOOST_NOEXCEPT_OR_NOTHROW +#endif +{ + std::free(p); +} + +bool f_run = false; + +int main() +{ + { + f_run = false; + boost::thread t( []() { f_run = true; } ); + t.join(); + BOOST_TEST(f_run == true); + } +#ifndef BOOST_MSVC + { + f_run = false; + try + { + throw_one = 0; + boost::thread t( []() { f_run = true; } ); + BOOST_TEST(false); + } + catch (...) + { + throw_one = 0xFFFF; + BOOST_TEST(!f_run); + } + } +#endif + + return boost::report_errors(); +} + +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/thread/test/threads/thread/constr/move_pass.cpp b/src/boost/libs/thread/test/threads/thread/constr/move_pass.cpp new file mode 100644 index 00000000..66f9d754 --- /dev/null +++ b/src/boost/libs/thread/test/threads/thread/constr/move_pass.cpp @@ -0,0 +1,94 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/thread.hpp> + +// class thread + +// thread(thread&& t); + +#include <boost/thread/thread_only.hpp> +#include <new> +#include <cstdlib> +#include <boost/detail/lightweight_test.hpp> + +class G +{ + int alive_; +public: + static int n_alive; + static bool op_run; + + G() : + alive_(1) + { + ++n_alive; + } + G(const G& g) : + alive_(g.alive_) + { + ++n_alive; + } + ~G() + { + alive_ = 0; + --n_alive; + } + + void operator()() + { + BOOST_TEST(alive_ == 1); + //BOOST_TEST(n_alive == 1); + op_run = true; + } + + void operator()(int i, double j) + { + BOOST_TEST(alive_ == 1); + std::cout << __FILE__ << ":" << __LINE__ <<" " << n_alive << std::endl; + //BOOST_TEST(n_alive == 1); + BOOST_TEST(i == 5); + BOOST_TEST(j == 5.5); + op_run = true; + } +}; + +int G::n_alive = 0; +bool G::op_run = false; + +boost::thread make_thread() { + return boost::thread(G(), 5, 5.5); +} + +int main() +{ + { + //BOOST_TEST(G::n_alive == 0); + BOOST_TEST(!G::op_run); + boost::thread t0((G())); + boost::thread::id id = t0.get_id(); + boost::thread t1((boost::move(t0))); + BOOST_TEST(t1.get_id() == id); + BOOST_TEST(t0.get_id() == boost::thread::id()); + t1.join(); + BOOST_TEST(G::op_run); + } + //BOOST_TEST(G::n_alive == 0); + { + boost::thread t1((BOOST_THREAD_MAKE_RV_REF(make_thread()))); + t1.join(); + BOOST_TEST(G::op_run); + } + //BOOST_TEST(G::n_alive == 0); + return boost::report_errors(); +} diff --git a/src/boost/libs/thread/test/threads/thread/destr/dtor_pass.cpp b/src/boost/libs/thread/test/threads/thread/destr/dtor_pass.cpp new file mode 100644 index 00000000..ea0e6bac --- /dev/null +++ b/src/boost/libs/thread/test/threads/thread/destr/dtor_pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/thread.hpp> + +// class thread + +// ~thread(); + +#define BOOST_THREAD_PROVIDES_THREAD_DESTRUCTOR_CALLS_TERMINATE_IF_JOINABLE + +#include <boost/thread/thread_only.hpp> +#include <new> +#include <cstdlib> +#include <boost/detail/lightweight_test.hpp> + +class G +{ + int alive_; +public: + static int n_alive; + static bool op_run; + + G() : + alive_(1) + { + ++n_alive; + } + G(const G& g) : + alive_(g.alive_) + { + ++n_alive; + } + ~G() + { + alive_ = 0; + --n_alive; + } + + void operator()() + { + BOOST_TEST(alive_ == 1); + //BOOST_TEST(n_alive == 1); + op_run = true; + } +}; + +int G::n_alive = 0; +bool G::op_run = false; + +void f1() +{ + std::exit(boost::report_errors()); +} + +int main() +{ + std::set_terminate(f1); + { + BOOST_TEST(G::n_alive == 0); + BOOST_TEST(!G::op_run); + boost::thread t( (G())); +#if defined BOOST_THREAD_USES_CHRONO + boost::this_thread::sleep_for(boost::chrono::milliseconds(250)); +#endif + BOOST_TEST(t.joinable()); + } + BOOST_TEST(false); + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/threads/thread/id/hash_pass.cpp b/src/boost/libs/thread/test/threads/thread/id/hash_pass.cpp new file mode 100644 index 00000000..6ce52c97 --- /dev/null +++ b/src/boost/libs/thread/test/threads/thread/id/hash_pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/thread.hpp> + +// <functional> + +// template <class T> +// struct hash +// : public unary_function<T, size_t> +// { +// size_t operator()(T val) const; +// }; + + +#include <boost/thread/thread_only.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + { + boost::thread::id id1; + boost::thread::id id2 = boost::this_thread::get_id(); + typedef boost::hash<boost::thread::id> H; + H h; + BOOST_TEST(h(id1) != h(id2)); + } + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/threads/thread/members/detach_pass.cpp b/src/boost/libs/thread/test/threads/thread/members/detach_pass.cpp new file mode 100644 index 00000000..92717533 --- /dev/null +++ b/src/boost/libs/thread/test/threads/thread/members/detach_pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/thread.hpp> + +// class thread + +// void detach(); + +#include <boost/thread/thread_only.hpp> +#include <new> +#include <cstdlib> +#include <cassert> +#include <boost/detail/lightweight_test.hpp> + +class G +{ + int alive_; +public: + static int n_alive; + static bool op_run; + + G() : + alive_(1) + { + ++n_alive; + } + G(const G& g) : + alive_(g.alive_) + { + ++n_alive; + } + ~G() + { + alive_ = 0; + --n_alive; + } + + void operator()() + { + BOOST_TEST(alive_ == 1); + //BOOST_TEST(n_alive == 1); + op_run = true; + } +}; + +int G::n_alive = 0; +bool G::op_run = false; + +int main() +{ + { + boost::thread t0( (G())); + BOOST_TEST(t0.joinable()); + t0.detach(); + BOOST_TEST(!t0.joinable()); +#if defined BOOST_THREAD_USES_CHRONO + boost::this_thread::sleep_for(boost::chrono::milliseconds(250)); + BOOST_TEST(G::op_run); + BOOST_TEST(G::n_alive == 0); +#endif + } + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/threads/thread/members/get_id_pass.cpp b/src/boost/libs/thread/test/threads/thread/members/get_id_pass.cpp new file mode 100644 index 00000000..dcaa7090 --- /dev/null +++ b/src/boost/libs/thread/test/threads/thread/members/get_id_pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/thread.hpp> + +// class thread + +// id get_id() const; + +#include <boost/thread/thread_only.hpp> +#include <new> +#include <cstdlib> +#include <cassert> +#include <boost/detail/lightweight_test.hpp> + +class G +{ + int alive_; +public: + static int n_alive; + static bool op_run; + + G() : + alive_(1) + { + ++n_alive; + } + G(const G& g) : + alive_(g.alive_) + { + ++n_alive; + } + ~G() + { + alive_ = 0; + --n_alive; + } + + void operator()() + { + BOOST_TEST(alive_ == 1); + //BOOST_TEST(n_alive == 1); + op_run = true; + } +}; + +int G::n_alive = 0; +bool G::op_run = false; + +int main() +{ + { + boost::thread t0( (G())); + //boost::thread::id id0 = t0.get_id(); + boost::thread t1; + boost::thread::id id1 = t1.get_id(); + BOOST_TEST(t0.get_id() != id1); + BOOST_TEST(t1.get_id() == boost::thread::id()); + t0.join(); + } + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/threads/thread/members/join_pass.cpp b/src/boost/libs/thread/test/threads/thread/members/join_pass.cpp new file mode 100644 index 00000000..f2d42b72 --- /dev/null +++ b/src/boost/libs/thread/test/threads/thread/members/join_pass.cpp @@ -0,0 +1,135 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/thread.hpp> + +// class thread + +// void join(); +#define BOOST_THREAD_VESRION 3 +#include <boost/thread/thread_only.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/locks.hpp> +#include <new> +#include <cstdlib> +#include <cassert> +#include <iostream> +#include <boost/detail/lightweight_test.hpp> + +class G +{ + int alive_; +public: + static int n_alive; + static bool op_run; + + G() : + alive_(1) + { + ++n_alive; + } + G(const G& g) : + alive_(g.alive_) + { + ++n_alive; + } + ~G() + { + alive_ = 0; + --n_alive; + } + + void operator()() + { + BOOST_TEST(alive_ == 1); + //BOOST_TEST(n_alive == 1); + op_run = true; + } +}; + +int G::n_alive = 0; +bool G::op_run = false; + +boost::thread* resource_deadlock_would_occur_th=0; +boost::mutex resource_deadlock_would_occur_mtx; +void resource_deadlock_would_occur_tester() +{ + try + { + boost::unique_lock<boost::mutex> lk(resource_deadlock_would_occur_mtx); + resource_deadlock_would_occur_th->join(); + BOOST_TEST(false); + } + catch (boost::system::system_error& e) + { + BOOST_TEST(e.code().value() == boost::system::errc::resource_deadlock_would_occur); + } + catch (...) + { + BOOST_TEST(false&&"exception thrown"); + } +} + +int main() +{ + { + boost::thread t0( (G())); + BOOST_TEST(t0.joinable()); + t0.join(); + BOOST_TEST(!t0.joinable()); + } + + { + boost::unique_lock<boost::mutex> lk(resource_deadlock_would_occur_mtx); + boost::thread t0( resource_deadlock_would_occur_tester ); + resource_deadlock_would_occur_th = &t0; + BOOST_TEST(t0.joinable()); + lk.unlock(); + boost::this_thread::sleep_for(boost::chrono::milliseconds(100)); + boost::unique_lock<boost::mutex> lk2(resource_deadlock_would_occur_mtx); + t0.join(); + BOOST_TEST(!t0.joinable()); + } + + { + boost::thread t0( (G())); + t0.detach(); + try + { + t0.join(); + BOOST_TEST(false); + } + catch (boost::system::system_error& e) + { + BOOST_TEST(e.code().value() == boost::system::errc::invalid_argument); + } + } + { + boost::thread t0( (G())); + BOOST_TEST(t0.joinable()); + t0.join(); + try + { + t0.join(); + BOOST_TEST(false); + } + catch (boost::system::system_error& e) + { + BOOST_TEST(e.code().value() == boost::system::errc::invalid_argument); + } + + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/threads/thread/members/joinable_pass.cpp b/src/boost/libs/thread/test/threads/thread/members/joinable_pass.cpp new file mode 100644 index 00000000..dcf09d1f --- /dev/null +++ b/src/boost/libs/thread/test/threads/thread/members/joinable_pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/thread.hpp> + +// class thread + +// bool joinable() const; + +#include <boost/thread/thread_only.hpp> +#include <new> +#include <cstdlib> +#include <cassert> +#include <boost/detail/lightweight_test.hpp> + +class G +{ + int alive_; +public: + static int n_alive; + static bool op_run; + + G() : + alive_(1) + { + ++n_alive; + } + G(const G& g) : + alive_(g.alive_) + { + ++n_alive; + } + ~G() + { + alive_ = 0; + --n_alive; + } + + void operator()() + { + BOOST_TEST(alive_ == 1); + //BOOST_TEST(n_alive == 1); + op_run = true; + } +}; + +int G::n_alive = 0; +bool G::op_run = false; + +int main() +{ + { + boost::thread t0( (G())); + BOOST_TEST(t0.joinable()); + t0.join(); + BOOST_TEST(!t0.joinable()); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/threads/thread/members/native_handle_pass.cpp b/src/boost/libs/thread/test/threads/thread/members/native_handle_pass.cpp new file mode 100644 index 00000000..01115da0 --- /dev/null +++ b/src/boost/libs/thread/test/threads/thread/members/native_handle_pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/thread.hpp> + +// class thread + +// native_handle_type native_handle(); + +#include <boost/thread/thread_only.hpp> +#include <new> +#include <cstdlib> +#include <cassert> +#include <boost/detail/lightweight_test.hpp> + +class G +{ + int alive_; +public: + static int n_alive; + static bool op_run; + + G() : + alive_(1) + { + ++n_alive; + } + G(const G& g) : + alive_(g.alive_) + { + ++n_alive; + } + ~G() + { + alive_ = 0; + --n_alive; + } + + void operator()() + { + BOOST_TEST(alive_ == 1); + //BOOST_TEST(n_alive == 1); + op_run = true; + } +}; + +int G::n_alive = 0; +bool G::op_run = false; + +int main() +{ + { + boost::thread t0( (G())); + // boost::thread::native_handle_type hdl = + (void)t0.native_handle(); + t0.join(); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/threads/thread/members/swap_pass.cpp b/src/boost/libs/thread/test/threads/thread/members/swap_pass.cpp new file mode 100644 index 00000000..16af2d1b --- /dev/null +++ b/src/boost/libs/thread/test/threads/thread/members/swap_pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/thread.hpp> + +// class thread + +// native_handle_type native_handle(); + +#include <boost/thread/thread_only.hpp> +#include <cstdlib> +#include <boost/detail/lightweight_test.hpp> + +class G +{ + int alive_; +public: + static int n_alive; + static bool op_run; + + G() : + alive_(1) + { + ++n_alive; + } + G(const G& g) : + alive_(g.alive_) + { + ++n_alive; + } + ~G() + { + alive_ = 0; + --n_alive; + } + + void operator()() + { + BOOST_TEST(alive_ == 1); + std::cout << n_alive << std::endl; + //BOOST_TEST(n_alive == 1); + op_run = true; + } +}; + +int G::n_alive = 0; +bool G::op_run = false; + +int main() +{ + { + boost::thread t0( (G())); + boost::thread::id id0 = t0.get_id(); + boost::thread t1; + boost::thread::id id1 = t1.get_id(); + t0.swap(t1); + BOOST_TEST(t0.get_id() == id1); + BOOST_TEST(t1.get_id() == id0); + t1.join(); + return boost::report_errors(); + } +} + diff --git a/src/boost/libs/thread/test/threads/thread/members/try_join_for_pass.cpp b/src/boost/libs/thread/test/threads/thread/members/try_join_for_pass.cpp new file mode 100644 index 00000000..5215d18d --- /dev/null +++ b/src/boost/libs/thread/test/threads/thread/members/try_join_for_pass.cpp @@ -0,0 +1,161 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/thread.hpp> + +// class thread + +// template <class Rep, class Period> +// bool try_join_for(const chrono::duration<Rep, Period>& rel_time); + +#define BOOST_THREAD_VESRION 3 +#include <boost/thread/thread_only.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/locks.hpp> +#include <new> +#include <cstdlib> +#include <cassert> +#include <iostream> +#include <boost/detail/lightweight_test.hpp> + +#if defined BOOST_THREAD_USES_CHRONO + +class G +{ + int alive_; +public: + static bool op_run; + + G() : + alive_(1) + { + } + G(const G& g) : + alive_(g.alive_) + { + } + ~G() + { + alive_ = 0; + } + + void operator()() + { + BOOST_TEST(alive_ == 1); + op_run = true; + } +}; + +bool G::op_run = false; + +boost::thread* resource_deadlock_would_occur_th=0; +boost::mutex resource_deadlock_would_occur_mtx; +void resource_deadlock_would_occur_tester() +{ + try + { + boost::unique_lock<boost::mutex> lk(resource_deadlock_would_occur_mtx); + resource_deadlock_would_occur_th->try_join_for(boost::chrono::milliseconds(50)); + BOOST_TEST(false); + } + catch (boost::system::system_error& e) + { + BOOST_TEST(e.code().value() == boost::system::errc::resource_deadlock_would_occur); + } + catch (...) + { + BOOST_TEST(false&&"exception thrown"); + } +} + +void th_250_ms() +{ + boost::this_thread::sleep_for(boost::chrono::milliseconds(250)); +} + +int main() +{ + { + boost::thread t0( (G())); + BOOST_TEST(t0.joinable()); + BOOST_TEST(t0.try_join_for(boost::chrono::milliseconds(250))); + BOOST_TEST(!t0.joinable()); + } + { + boost::thread t0( (th_250_ms)); + BOOST_TEST(!t0.try_join_for(boost::chrono::milliseconds(50))); + t0.join(); + } + + { + boost::unique_lock<boost::mutex> lk(resource_deadlock_would_occur_mtx); + boost::thread t0( resource_deadlock_would_occur_tester ); + resource_deadlock_would_occur_th = &t0; + BOOST_TEST(t0.joinable()); + lk.unlock(); + boost::this_thread::sleep_for(boost::chrono::milliseconds(250)); + boost::unique_lock<boost::mutex> lk2(resource_deadlock_would_occur_mtx); + t0.join(); + BOOST_TEST(!t0.joinable()); + } + + { + boost::thread t0( (G())); + t0.detach(); + try + { + t0.try_join_for(boost::chrono::milliseconds(50)); + BOOST_TEST(false); + } + catch (boost::system::system_error& e) + { + BOOST_TEST(e.code().value() == boost::system::errc::invalid_argument); + } + } + { + boost::thread t0( (G())); + BOOST_TEST(t0.joinable()); + t0.join(); + try + { + t0.try_join_for(boost::chrono::milliseconds(50)); + BOOST_TEST(false); + } + catch (boost::system::system_error& e) + { + BOOST_TEST(e.code().value() == boost::system::errc::invalid_argument); + } + + } + { + boost::thread t0( (G())); + BOOST_TEST(t0.joinable()); + t0.try_join_for(boost::chrono::milliseconds(250)); + try + { + t0.join(); + BOOST_TEST(false); + } + catch (boost::system::system_error& e) + { + BOOST_TEST(e.code().value() == boost::system::errc::invalid_argument); + } + + } + + return boost::report_errors(); +} + +#else +#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported" +#endif diff --git a/src/boost/libs/thread/test/threads/thread/members/try_join_until_pass.cpp b/src/boost/libs/thread/test/threads/thread/members/try_join_until_pass.cpp new file mode 100644 index 00000000..749ff5b0 --- /dev/null +++ b/src/boost/libs/thread/test/threads/thread/members/try_join_until_pass.cpp @@ -0,0 +1,162 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/thread.hpp> + +// class thread + +// template <class Clock, class Duration> +// bool try_join_until(const chrono::time_point<Clock, Duration>& t); + +#define BOOST_THREAD_VESRION 3 +#include <boost/thread/thread_only.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/locks.hpp> +#include <new> +#include <cstdlib> +#include <cassert> +#include <iostream> +#include <boost/detail/lightweight_test.hpp> + +#if defined BOOST_THREAD_USES_CHRONO + +class G +{ + int alive_; +public: + static bool op_run; + + G() : + alive_(1) + { + } + G(const G& g) : + alive_(g.alive_) + { + } + ~G() + { + alive_ = 0; + } + + void operator()() + { + BOOST_TEST(alive_ == 1); + op_run = true; + } +}; + +bool G::op_run = false; + +boost::thread* resource_deadlock_would_occur_th=0; +boost::mutex resource_deadlock_would_occur_mtx; +void resource_deadlock_would_occur_tester() +{ + try + { + boost::unique_lock<boost::mutex> lk(resource_deadlock_would_occur_mtx); + resource_deadlock_would_occur_th->try_join_until(boost::chrono::steady_clock::now()+boost::chrono::milliseconds(50)); + BOOST_TEST(false); + } + catch (boost::system::system_error& e) + { + BOOST_TEST(e.code().value() == boost::system::errc::resource_deadlock_would_occur); + } + catch (...) + { + BOOST_TEST(false&&"exception thrown"); + } +} + +void th_250_ms() +{ + boost::this_thread::sleep_for(boost::chrono::milliseconds(250)); +} + + +int main() +{ + { + boost::thread t0( (G())); + BOOST_TEST(t0.joinable()); + t0.try_join_until(boost::chrono::steady_clock::now()+boost::chrono::milliseconds(250)); + BOOST_TEST(!t0.joinable()); + } + { + boost::thread t0( (th_250_ms)); + BOOST_TEST(!t0.try_join_until(boost::chrono::steady_clock::now()+boost::chrono::milliseconds(50))); + t0.join(); + } + + { + boost::unique_lock<boost::mutex> lk(resource_deadlock_would_occur_mtx); + boost::thread t0( resource_deadlock_would_occur_tester ); + resource_deadlock_would_occur_th = &t0; + BOOST_TEST(t0.joinable()); + lk.unlock(); + boost::this_thread::sleep_for(boost::chrono::milliseconds(250)); + boost::unique_lock<boost::mutex> lk2(resource_deadlock_would_occur_mtx); + t0.join(); + BOOST_TEST(!t0.joinable()); + } + + { + boost::thread t0( (G())); + t0.detach(); + try + { + t0.try_join_until(boost::chrono::steady_clock::now()+boost::chrono::milliseconds(50)); + BOOST_TEST(false); + } + catch (boost::system::system_error& e) + { + BOOST_TEST(e.code().value() == boost::system::errc::invalid_argument); + } + } + { + boost::thread t0( (G())); + BOOST_TEST(t0.joinable()); + t0.join(); + try + { + t0.try_join_until(boost::chrono::steady_clock::now()+boost::chrono::milliseconds(50)); + BOOST_TEST(false); + } + catch (boost::system::system_error& e) + { + BOOST_TEST(e.code().value() == boost::system::errc::invalid_argument); + } + + } + { + boost::thread t0( (G())); + BOOST_TEST(t0.joinable()); + t0.try_join_until(boost::chrono::steady_clock::now()+boost::chrono::milliseconds(250)); + try + { + t0.join(); + BOOST_TEST(false); + } + catch (boost::system::system_error& e) + { + BOOST_TEST(e.code().value() == boost::system::errc::invalid_argument); + } + + } + + return boost::report_errors(); +} + +#else +#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported" +#endif diff --git a/src/boost/libs/thread/test/threads/thread/non_members/swap_pass.cpp b/src/boost/libs/thread/test/threads/thread/non_members/swap_pass.cpp new file mode 100644 index 00000000..eb6faf15 --- /dev/null +++ b/src/boost/libs/thread/test/threads/thread/non_members/swap_pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/thread.hpp> + +// void swap(thread& x, thread& y); + +#include <boost/thread/thread_only.hpp> +#include <new> +#include <cstdlib> +#include <cassert> +#include <boost/detail/lightweight_test.hpp> + +class G +{ + int alive_; +public: + static int n_alive; + static bool op_run; + + G() : + alive_(1) + { + ++n_alive; + } + G(const G& g) : + alive_(g.alive_) + { + ++n_alive; + } + ~G() + { + alive_ = 0; + --n_alive; + } + + void operator()() + { + BOOST_TEST(alive_ == 1); + //BOOST_TEST(n_alive == 1); + op_run = true; + } +}; + +int G::n_alive = 0; +bool G::op_run = false; + +int main() +{ + { + boost::thread t0( (G())); + boost::thread::id id0 = t0.get_id(); + boost::thread t1; + boost::thread::id id1 = t1.get_id(); + swap(t0, t1); + BOOST_TEST(t0.get_id() == id1); + BOOST_TEST(t1.get_id() == id0); + t1.join(); + } + return boost::report_errors(); +} + diff --git a/src/boost/libs/thread/test/threads/thread/static/hardware_concurrency_pass.cpp b/src/boost/libs/thread/test/threads/thread/static/hardware_concurrency_pass.cpp new file mode 100644 index 00000000..2a2a227e --- /dev/null +++ b/src/boost/libs/thread/test/threads/thread/static/hardware_concurrency_pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Copyright (C) 2011 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// <boost/thread/thread.hpp> + +// class thread + +// static unsigned hardware_concurrency(); + +#include <boost/thread/thread_only.hpp> +#include <boost/detail/lightweight_test.hpp> + +int main() +{ + BOOST_TEST(boost::thread::hardware_concurrency() > 0); + return boost::report_errors(); +} + |