diff --git a/test/sync/conditions/condition_variable/assign_fail.cpp b/test/sync/conditions/condition_variable/assign_fail.cpp new file mode 100644 index 00000000..da546097 --- /dev/null +++ b/test/sync/conditions/condition_variable/assign_fail.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) + +// + +// class condition_variable; + +// condition_variable& operator=(const condition_variable&) = delete; + +#include + +int fail() +{ + boost::condition_variable cv0; + boost::condition_variable cv1; + cv1 = cv0; +} + diff --git a/test/sync/conditions/condition_variable/copy_fail.cpp b/test/sync/conditions/condition_variable/copy_fail.cpp new file mode 100644 index 00000000..472b564f --- /dev/null +++ b/test/sync/conditions/condition_variable/copy_fail.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) + +// + +// class condition_variable; + +// condition_variable(const condition_variable&) = delete; + +#include +#include + +int fail() +{ + boost::condition_variable cv0; + boost::condition_variable cv1(cv0); +} + diff --git a/test/sync/conditions/condition_variable/default_pass.cpp b/test/sync/conditions/condition_variable/default_pass.cpp new file mode 100644 index 00000000..5adc6bf6 --- /dev/null +++ b/test/sync/conditions/condition_variable/default_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) + +// + +// class condition_variable; + +// condition_variable(const condition_variable&) = delete; + +#include +#include + +int main() +{ + boost::condition_variable cv0; + return boost::report_errors(); +} + diff --git a/test/sync/conditions/condition_variable/dtor_pass.cpp b/test/sync/conditions/condition_variable/dtor_pass.cpp new file mode 100644 index 00000000..533898ed --- /dev/null +++ b/test/sync/conditions/condition_variable/dtor_pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class condition_variable; + +// condition_variable(const condition_variable&) = delete; + +#include +#include +#include +#include +#include + +boost::condition_variable* cv; +boost::mutex m; +typedef boost::unique_lock Lock; + +bool f_ready = false; +bool g_ready = false; + +void f() +{ + Lock lk(m); + f_ready = true; + cv->notify_one(); + cv->wait(lk); + delete cv; +} + +void g() +{ + Lock lk(m); + g_ready = true; + cv->notify_one(); + while (!f_ready) + { + cv->wait(lk); + } + cv->notify_one(); +} + +int main() +{ + cv = new boost::condition_variable; + boost::thread th2(g); + Lock lk(m); + while (!g_ready) + { + cv->wait(lk); + } + lk.unlock(); + boost::thread th1(f); + th1.join(); + th2.join(); + return boost::report_errors(); +} + diff --git a/test/sync/conditions/condition_variable/native_handle_pass.cpp b/test/sync/conditions/condition_variable/native_handle_pass.cpp new file mode 100644 index 00000000..0df5fff6 --- /dev/null +++ b/test/sync/conditions/condition_variable/native_handle_pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class condition_variable; + +// condition_variable(const condition_variable&) = delete; + +#include + +#include +#include + +int main() +{ + //BOOST_STATIC_ASSERT((boost::is_same::value)); + boost::condition_variable cv; + boost::condition_variable::native_handle_type h = cv.native_handle(); + BOOST_TEST(h != 0); + return boost::report_errors(); +} + diff --git a/test/sync/conditions/condition_variable/wait_for_pass.cpp b/test/sync/conditions/condition_variable/wait_for_pass.cpp new file mode 100644 index 00000000..13323643 --- /dev/null +++ b/test/sync/conditions/condition_variable/wait_for_pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class condition_variable; + +// condition_variable(const condition_variable&) = delete; + +#include +#include +#include +#include + +boost::condition_variable cv; +boost::mutex mut; + +int test1 = 0; +int test2 = 0; + +int runs = 0; + +void f() +{ + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds milliseconds; + boost::unique_lock lk(mut); + BOOST_TEST(test2 == 0); + test1 = 1; + cv.notify_one(); + Clock::time_point t0 = Clock::now(); + while (test2 == 0 && cv.wait_for(lk, milliseconds(250)) == boost::cv_status::no_timeout) + ; + Clock::time_point t1 = Clock::now(); + if (runs == 0) + { + BOOST_TEST(t1 - t0 < milliseconds(250)); + BOOST_TEST(test2 != 0); + } + else + { + BOOST_TEST(t1 - t0 - milliseconds(250) < milliseconds(5)); + BOOST_TEST(test2 == 0); + } + ++runs; +} + +int main() +{ + { + boost::unique_lock lk(mut); + boost::thread t(f); + BOOST_TEST(test1 == 0); + while (test1 == 0) + cv.wait(lk); + BOOST_TEST(test1 != 0); + test2 = 1; + lk.unlock(); + cv.notify_one(); + t.join(); + } + test1 = 0; + test2 = 0; + { + boost::unique_lock lk(mut); + boost::thread t(f); + BOOST_TEST(test1 == 0); + while (test1 == 0) + cv.wait(lk); + BOOST_TEST(test1 != 0); + lk.unlock(); + t.join(); + } + + return boost::report_errors(); +} + diff --git a/test/sync/conditions/condition_variable/wait_for_pred_pass.cpp b/test/sync/conditions/condition_variable/wait_for_pred_pass.cpp new file mode 100644 index 00000000..b0825585 --- /dev/null +++ b/test/sync/conditions/condition_variable/wait_for_pred_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) + +// + +// class condition_variable; + +// condition_variable(const condition_variable&) = delete; + +#include +#include +#include +#include + +class Pred +{ + int& i_; +public: + explicit Pred(int& i) : + i_(i) + { + } + + bool operator()() + { + return i_ != 0; + } +}; + +boost::condition_variable cv; +boost::mutex mut; + +int test1 = 0; +int test2 = 0; + +int runs = 0; + +void f() +{ + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds milliseconds; + boost::unique_lock < boost::mutex > lk(mut); + BOOST_TEST(test2 == 0); + test1 = 1; + cv.notify_one(); + Clock::time_point t0 = Clock::now(); + bool r = cv.wait_for(lk, milliseconds(250), Pred(test2)); + Clock::time_point t1 = Clock::now(); + if (runs == 0) + { + BOOST_TEST(t1 - t0 < milliseconds(250)); + BOOST_TEST(test2 != 0); + } + else + { + BOOST_TEST(t1 - t0 - milliseconds(250) < milliseconds(2)); + BOOST_TEST(test2 == 0); + } + ++runs; +} + +int main() +{ + { + boost::unique_lock < boost::mutex > lk(mut); + boost::thread t(f); + BOOST_TEST(test1 == 0); + while (test1 == 0) + cv.wait(lk); + BOOST_TEST(test1 != 0); + test2 = 1; + lk.unlock(); + cv.notify_one(); + t.join(); + } + test1 = 0; + test2 = 0; + { + boost::unique_lock < boost::mutex > lk(mut); + boost::thread t(f); + BOOST_TEST(test1 == 0); + while (test1 == 0) + cv.wait(lk); + BOOST_TEST(test1 != 0); + lk.unlock(); + t.join(); + } + + return boost::report_errors(); +} + diff --git a/test/sync/conditions/condition_variable/wait_until_pass.cpp b/test/sync/conditions/condition_variable/wait_until_pass.cpp new file mode 100644 index 00000000..4fcd7b58 --- /dev/null +++ b/test/sync/conditions/condition_variable/wait_until_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) + +// + +// class condition_variable; + +// condition_variable(const condition_variable&) = delete; + +#include +#include +#include +#include + +struct Clock +{ + typedef boost::chrono::milliseconds duration; + typedef duration::rep rep; + typedef duration::period period; + typedef boost::chrono::time_point time_point; + static const bool is_steady = true; + + static time_point now() + { + using namespace boost::chrono; + return time_point(duration_cast (steady_clock::now().time_since_epoch())); + } +}; + +boost::condition_variable cv; +boost::mutex mut; + +int test1 = 0; +int test2 = 0; + +int runs = 0; + +void f() +{ + boost::unique_lock < boost::mutex > lk(mut); + BOOST_TEST(test2 == 0); + test1 = 1; + cv.notify_one(); + Clock::time_point t0 = Clock::now(); + Clock::time_point t = t0 + Clock::duration(250); + while (test2 == 0 && cv.wait_until(lk, t) == boost::cv_status::no_timeout) + ; + Clock::time_point t1 = Clock::now(); + if (runs == 0) + { + BOOST_TEST(t1 - t0 < Clock::duration(250)); + BOOST_TEST(test2 != 0); + } + else + { + BOOST_TEST(t1 - t0 - Clock::duration(250) < Clock::duration(5)); + BOOST_TEST(test2 == 0); + } + ++runs; +} + +int main() +{ + { + boost::unique_lock < boost::mutex > lk(mut); + boost::thread t(f); + BOOST_TEST(test1 == 0); + while (test1 == 0) + cv.wait(lk); + BOOST_TEST(test1 != 0); + test2 = 1; + lk.unlock(); + cv.notify_one(); + t.join(); + } + test1 = 0; + test2 = 0; + { + boost::unique_lock < boost::mutex > lk(mut); + boost::thread t(f); + BOOST_TEST(test1 == 0); + while (test1 == 0) + cv.wait(lk); + BOOST_TEST(test1 != 0); + lk.unlock(); + t.join(); + } + + return boost::report_errors(); +} + diff --git a/test/sync/conditions/condition_variable/wait_until_pred_pass.cpp b/test/sync/conditions/condition_variable/wait_until_pred_pass.cpp new file mode 100644 index 00000000..3ca44544 --- /dev/null +++ b/test/sync/conditions/condition_variable/wait_until_pred_pass.cpp @@ -0,0 +1,117 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class condition_variable; + +// condition_variable(const condition_variable&) = delete; + +#include +#include +#include +#include + +struct Clock +{ + typedef boost::chrono::milliseconds duration; + typedef duration::rep rep; + typedef duration::period period; + typedef boost::chrono::time_point time_point; + static const bool is_steady = true; + + static time_point now() + { + using namespace boost::chrono; + return time_point(duration_cast (steady_clock::now().time_since_epoch())); + } +}; + +class Pred +{ + int& i_; +public: + explicit Pred(int& i) : + i_(i) + { + } + + bool operator()() + { + return i_ != 0; + } +}; + +boost::condition_variable cv; +boost::mutex mut; + +int test1 = 0; +int test2 = 0; + +int runs = 0; + +void f() +{ + boost::unique_lock lk(mut); + BOOST_TEST(test2 == 0); + test1 = 1; + cv.notify_one(); + Clock::time_point t0 = Clock::now(); + Clock::time_point t = t0 + Clock::duration(250); + bool r = cv.wait_until(lk, t, Pred(test2)); + Clock::time_point t1 = Clock::now(); + if (runs == 0) + { + BOOST_TEST(t1 - t0 < Clock::duration(250)); + BOOST_TEST(test2 != 0); + BOOST_TEST(r); + } + else + { + BOOST_TEST(t1 - t0 - Clock::duration(250) < Clock::duration(2)); + BOOST_TEST(test2 == 0); + BOOST_TEST(!r); + } + ++runs; +} + +int main() +{ + { + boost::unique_lock lk(mut); + boost::thread t(f); + BOOST_TEST(test1 == 0); + while (test1 == 0) + cv.wait(lk); + BOOST_TEST(test1 != 0); + test2 = 1; + lk.unlock(); + cv.notify_one(); + t.join(); + } + test1 = 0; + test2 = 0; + { + boost::unique_lock lk(mut); + boost::thread t(f); + BOOST_TEST(test1 == 0); + while (test1 == 0) + cv.wait(lk); + BOOST_TEST(test1 != 0); + lk.unlock(); + t.join(); + } + + return boost::report_errors(); +} + diff --git a/test/sync/conditions/condition_variable_any/assign_fail.cpp b/test/sync/conditions/condition_variable_any/assign_fail.cpp new file mode 100644 index 00000000..806cc953 --- /dev/null +++ b/test/sync/conditions/condition_variable_any/assign_fail.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) + +// + +// class condition_variable_any; + +// condition_variable_any& operator=(const condition_variable_any&) = delete; + +#include + +int fail() +{ + boost::condition_variable_any cv0; + boost::condition_variable_any cv1; + cv1 = cv0; +} + diff --git a/test/sync/conditions/condition_variable_any/copy_fail.cpp b/test/sync/conditions/condition_variable_any/copy_fail.cpp new file mode 100644 index 00000000..55d12076 --- /dev/null +++ b/test/sync/conditions/condition_variable_any/copy_fail.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) + +// + +// class condition_variable_any; + +// condition_variable_any(const condition_variable_any&) = delete; + +#include +#include + +int fail() +{ + boost::condition_variable_any cv0; + boost::condition_variable_any cv1(cv0); +} + diff --git a/test/sync/conditions/condition_variable_any/default_pass.cpp b/test/sync/conditions/condition_variable_any/default_pass.cpp new file mode 100644 index 00000000..21116ebc --- /dev/null +++ b/test/sync/conditions/condition_variable_any/default_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) + +// + +// class condition_variable_any; + +// condition_variable_any(const condition_variable_any&) = delete; + +#include +#include + +int main() +{ + boost::condition_variable_any cv0; + return boost::report_errors(); +} + diff --git a/test/sync/conditions/condition_variable_any/dtor_pass.cpp b/test/sync/conditions/condition_variable_any/dtor_pass.cpp new file mode 100644 index 00000000..7734d93b --- /dev/null +++ b/test/sync/conditions/condition_variable_any/dtor_pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class condition_variable_any; + +// condition_variable_any(const condition_variable_any&) = delete; + +#include +#include +#include +#include +#include + +boost::condition_variable_any* cv; +boost::timed_mutex m; +typedef boost::unique_lock Lock; + +bool f_ready = false; +bool g_ready = false; + +void f() +{ + Lock lk(m); + f_ready = true; + cv->notify_one(); + cv->wait(lk); + delete cv; +} + +void g() +{ + Lock lk(m); + g_ready = true; + cv->notify_one(); + while (!f_ready) + { + cv->wait(lk); + } + cv->notify_one(); +} + +int main() +{ + cv = new boost::condition_variable_any; + boost::thread th2(g); + Lock lk(m); + while (!g_ready) + { + cv->wait(lk); + } + lk.unlock(); + boost::thread th1(f); + th1.join(); + th2.join(); + return boost::report_errors(); +} + diff --git a/test/sync/conditions/condition_variable_any/wait_for_pass.cpp b/test/sync/conditions/condition_variable_any/wait_for_pass.cpp new file mode 100644 index 00000000..e74ee6d2 --- /dev/null +++ b/test/sync/conditions/condition_variable_any/wait_for_pass.cpp @@ -0,0 +1,92 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class condition_variable_any; + +// condition_variable_any(const condition_variable_any&) = delete; + +#include +#include +#include +#include + +boost::condition_variable_any cv; + +typedef boost::timed_mutex L0; +typedef boost::unique_lock L1; + +L0 m0; + +int test1 = 0; +int test2 = 0; + +int runs = 0; + +void f() +{ + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds milliseconds; + L1 lk(m0); + BOOST_TEST(test2 == 0); + test1 = 1; + cv.notify_one(); + Clock::time_point t0 = Clock::now(); + while (test2 == 0 && + cv.wait_for(lk, milliseconds(250)) == boost::cv_status::no_timeout) + ; + Clock::time_point t1 = Clock::now(); + if (runs == 0) + { + BOOST_TEST(t1 - t0 < milliseconds(250)); + BOOST_TEST(test2 != 0); + } + else + { + BOOST_TEST(t1 - t0 - milliseconds(250) < milliseconds(5)); + BOOST_TEST(test2 == 0); + } + ++runs; +} + +int main() +{ + { + L1 lk(m0); + boost::thread t(f); + BOOST_TEST(test1 == 0); + while (test1 == 0) + cv.wait(lk); + BOOST_TEST(test1 != 0); + test2 = 1; + lk.unlock(); + cv.notify_one(); + t.join(); + } + test1 = 0; + test2 = 0; + { + L1 lk(m0); + boost::thread t(f); + BOOST_TEST(test1 == 0); + while (test1 == 0) + cv.wait(lk); + BOOST_TEST(test1 != 0); + lk.unlock(); + t.join(); + } + + return boost::report_errors(); +} + diff --git a/test/sync/conditions/condition_variable_any/wait_for_pred_pass.cpp b/test/sync/conditions/condition_variable_any/wait_for_pred_pass.cpp new file mode 100644 index 00000000..e29dd951 --- /dev/null +++ b/test/sync/conditions/condition_variable_any/wait_for_pred_pass.cpp @@ -0,0 +1,105 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class condition_variable_any; + +// condition_variable_any(const condition_variable_any&) = delete; + +#include +#include +#include +#include + +class Pred +{ + int& i_; +public: + explicit Pred(int& i) : + i_(i) + { + } + + bool operator()() + { + return i_ != 0; + } +}; + +boost::condition_variable_any cv; + +typedef boost::timed_mutex L0; +typedef boost::unique_lock L1; + +L0 m0; + +int test1 = 0; +int test2 = 0; + +int runs = 0; + +void f() +{ + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds milliseconds; + L1 lk(m0); + BOOST_TEST(test2 == 0); + test1 = 1; + cv.notify_one(); + Clock::time_point t0 = Clock::now(); + bool r = cv.wait_for(lk, milliseconds(250), Pred(test2)); + Clock::time_point t1 = Clock::now(); + if (runs == 0) + { + BOOST_TEST(t1 - t0 < milliseconds(250)); + BOOST_TEST(test2 != 0); + } + else + { + BOOST_TEST(t1 - t0 - milliseconds(250) < milliseconds(5)); + BOOST_TEST(test2 == 0); + } + ++runs; +} + +int main() +{ + { + L1 lk(m0); + boost::thread t(f); + BOOST_TEST(test1 == 0); + while (test1 == 0) + cv.wait(lk); + BOOST_TEST(test1 != 0); + test2 = 1; + lk.unlock(); + cv.notify_one(); + t.join(); + } + test1 = 0; + test2 = 0; + { + L1 lk(m0); + boost::thread t(f); + BOOST_TEST(test1 == 0); + while (test1 == 0) + cv.wait(lk); + BOOST_TEST(test1 != 0); + lk.unlock(); + t.join(); + } + + return boost::report_errors(); +} + diff --git a/test/sync/conditions/condition_variable_any/wait_until_pass.cpp b/test/sync/conditions/condition_variable_any/wait_until_pass.cpp new file mode 100644 index 00000000..17b91d54 --- /dev/null +++ b/test/sync/conditions/condition_variable_any/wait_until_pass.cpp @@ -0,0 +1,105 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class condition_variable_any; + +// condition_variable_any(const condition_variable_any&) = delete; + +#include +#include +#include +#include + +struct Clock +{ + typedef boost::chrono::milliseconds duration; + typedef duration::rep rep; + typedef duration::period period; + typedef boost::chrono::time_point time_point; + static const bool is_steady = true; + + static time_point now() + { + using namespace boost::chrono; + return time_point(duration_cast (steady_clock::now().time_since_epoch())); + } +}; + +boost::condition_variable_any cv; + +typedef boost::timed_mutex L0; +typedef boost::unique_lock L1; + +L0 m0; + +int test1 = 0; +int test2 = 0; + +int runs = 0; + +void f() +{ + L1 lk(m0); + BOOST_TEST(test2 == 0); + test1 = 1; + cv.notify_one(); + Clock::time_point t0 = Clock::now(); + Clock::time_point t = t0 + Clock::duration(250); + while (test2 == 0 && cv.wait_until(lk, t) == boost::cv_status::no_timeout) + ; + Clock::time_point t1 = Clock::now(); + if (runs == 0) + { + BOOST_TEST(t1 - t0 < Clock::duration(250)); + BOOST_TEST(test2 != 0); + } + else + { + BOOST_TEST(t1 - t0 - Clock::duration(250) < Clock::duration(5)); + BOOST_TEST(test2 == 0); + } + ++runs; +} + +int main() +{ + { + L1 lk(m0); + boost::thread t(f); + BOOST_TEST(test1 == 0); + while (test1 == 0) + cv.wait(lk); + BOOST_TEST(test1 != 0); + test2 = 1; + lk.unlock(); + cv.notify_one(); + t.join(); + } + test1 = 0; + test2 = 0; + { + L1 lk(m0); + boost::thread t(f); + BOOST_TEST(test1 == 0); + while (test1 == 0) + cv.wait(lk); + BOOST_TEST(test1 != 0); + lk.unlock(); + t.join(); + } + + return boost::report_errors(); +} + diff --git a/test/sync/conditions/condition_variable_any/wait_until_pred_pass.cpp b/test/sync/conditions/condition_variable_any/wait_until_pred_pass.cpp new file mode 100644 index 00000000..437bf332 --- /dev/null +++ b/test/sync/conditions/condition_variable_any/wait_until_pred_pass.cpp @@ -0,0 +1,121 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class condition_variable_any; + +// condition_variable_any(const condition_variable_any&) = delete; + +#include +#include +#include +#include + +struct Clock +{ + typedef boost::chrono::milliseconds duration; + typedef duration::rep rep; + typedef duration::period period; + typedef boost::chrono::time_point time_point; + static const bool is_steady = true; + + static time_point now() + { + using namespace boost::chrono; + return time_point(duration_cast (steady_clock::now().time_since_epoch())); + } +}; + +class Pred +{ + int& i_; +public: + explicit Pred(int& i) : + i_(i) + { + } + + bool operator()() + { + return i_ != 0; + } +}; + +boost::condition_variable_any cv; + +typedef boost::timed_mutex L0; +typedef boost::unique_lock L1; + +L0 m0; + +int test1 = 0; +int test2 = 0; + +int runs = 0; + +void f() +{ + L1 lk(m0); + BOOST_TEST(test2 == 0); + test1 = 1; + cv.notify_one(); + Clock::time_point t0 = Clock::now(); + Clock::time_point t = t0 + Clock::duration(250); + bool r = cv.wait_until(lk, t, Pred(test2)); + Clock::time_point t1 = Clock::now(); + if (runs == 0) + { + BOOST_TEST(t1 - t0 < Clock::duration(250)); + BOOST_TEST(test2 != 0); + BOOST_TEST(r); + } + else + { + BOOST_TEST(t1 - t0 - Clock::duration(250) < Clock::duration(2)); + BOOST_TEST(test2 == 0); + BOOST_TEST(!r); + } + ++runs; +} + +int main() +{ + { + L1 lk(m0); + boost::thread t(f); + BOOST_TEST(test1 == 0); + while (test1 == 0) + cv.wait(lk); + BOOST_TEST(test1 != 0); + test2 = 1; + lk.unlock(); + cv.notify_one(); + t.join(); + } + test1 = 0; + test2 = 0; + { + L1 lk(m0); + boost::thread t(f); + BOOST_TEST(test1 == 0); + while (test1 == 0) + cv.wait(lk); + BOOST_TEST(test1 != 0); + lk.unlock(); + t.join(); + } + + return boost::report_errors(); +} + diff --git a/test/sync/conditions/cv_status/cv_status_pass.cpp b/test/sync/conditions/cv_status/cv_status_pass.cpp new file mode 100644 index 00000000..becac4da --- /dev/null +++ b/test/sync/conditions/cv_status/cv_status_pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class thread + +// static unsigned hardware_concurrency(); + +#include +#include + +int main() +{ + { + BOOST_TEST(boost::cv_status::no_timeout != boost::cv_status::timeout); + } + { + boost::cv_status st = boost::cv_status::no_timeout; + BOOST_TEST(st == boost::cv_status::no_timeout); + BOOST_TEST(boost::cv_status::no_timeout==st); + BOOST_TEST(st != boost::cv_status::timeout); + BOOST_TEST(boost::cv_status::timeout!=st); + } + { + boost::cv_status st = boost::cv_status::timeout; + BOOST_TEST(st == boost::cv_status::timeout); + BOOST_TEST(boost::cv_status::timeout==st); + BOOST_TEST(st != boost::cv_status::no_timeout); + BOOST_TEST(boost::cv_status::no_timeout!=st); + } + { + boost::cv_status st; + st = boost::cv_status::no_timeout; + BOOST_TEST(st == boost::cv_status::no_timeout); + BOOST_TEST(boost::cv_status::no_timeout==st); + BOOST_TEST(st != boost::cv_status::timeout); + BOOST_TEST(boost::cv_status::timeout!=st); + } + { + boost::cv_status st; + st = boost::cv_status::timeout; + BOOST_TEST(st == boost::cv_status::timeout); + BOOST_TEST(boost::cv_status::timeout==st); + BOOST_TEST(st != boost::cv_status::no_timeout); + BOOST_TEST(boost::cv_status::no_timeout!=st); + } + return boost::report_errors(); +} + diff --git a/test/sync/futures/async/async_pass.cpp b/test/sync/futures/async/async_pass.cpp new file mode 100644 index 00000000..b13c844e --- /dev/null +++ b/test/sync/futures/async/async_pass.cpp @@ -0,0 +1,184 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// template +// future::type> +// async(F&& f, Args&&... args); + +// template +// future::type> +// async(launch policy, F&& f, Args&&... args); + + +#include +#include +#include + +typedef boost::chrono::high_resolution_clock Clock; +typedef boost::chrono::milliseconds ms; + +int f0() +{ + boost::this_thread::sleep_for(ms(200)); + return 3; +} + +int i = 0; + +int& f1() +{ + boost::this_thread::sleep_for(ms(200)); + return i; +} + +void f2() +{ + boost::this_thread::sleep_for(ms(200)); +} + +boost::unique_ptr f3(int i) +{ + boost::this_thread::sleep_for(ms(200)); + return boost::unique_ptr(new int(i)); +} + +boost::unique_ptr f4(boost::unique_ptr&& p) +{ + boost::this_thread::sleep_for(ms(200)); + return boost::move(p); +} + +int main() +{ + { + boost::future f = boost::async(f0); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + BOOST_TEST(f.get() == 3); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 < ms(100)); + } + { + boost::future f = boost::async(boost::launch::async, f0); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + BOOST_TEST(f.get() == 3); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 < ms(100)); + } + { + boost::future f = boost::async(boost::launch::any, f0); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + BOOST_TEST(f.get() == 3); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 < ms(100)); + } + { + boost::future f = boost::async(boost::launch::deferred, f0); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + BOOST_TEST(f.get() == 3); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 > ms(100)); + } + + { + boost::future f = boost::async(f1); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + BOOST_TEST(&f.get() == &i); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 < ms(100)); + } + { + boost::future f = boost::async(boost::launch::async, f1); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + BOOST_TEST(&f.get() == &i); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 < ms(100)); + } + { + boost::future f = boost::async(boost::launch::any, f1); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + BOOST_TEST(&f.get() == &i); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 < ms(100)); + } + { + boost::future f = boost::async(boost::launch::deferred, f1); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + BOOST_TEST(&f.get() == &i); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 > ms(100)); + } + + { + boost::future f = boost::async(f2); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + f.get(); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 < ms(100)); + } + { + boost::future f = boost::async(boost::launch::async, f2); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + f.get(); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 < ms(100)); + } + { + boost::future f = boost::async(boost::launch::any, f2); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + f.get(); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 < ms(100)); + } + { + boost::future f = boost::async(boost::launch::deferred, f2); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + f.get(); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 > ms(100)); + } + + { + boost::future> f = boost::async(f3, 3); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + BOOST_TEST(*f.get() == 3); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 < ms(100)); + } + + { + boost::future> f = boost::async(f4, boost::unique_ptr(new int(3))); + boost::this_thread::sleep_for(ms(300)); + Clock::time_point t0 = Clock::now(); + BOOST_TEST(*f.get() == 3); + Clock::time_point t1 = Clock::now(); + BOOST_TEST(t1 - t0 < ms(100)); + } + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/locks/unique_lock/cons/adopt_lock_pass.cpp b/test/sync/mutual_exclusion/locks/unique_lock/cons/adopt_lock_pass.cpp new file mode 100644 index 00000000..1d40d903 --- /dev/null +++ b/test/sync/mutual_exclusion/locks/unique_lock/cons/adopt_lock_pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// template class unique_lock; + +// unique_lock(mutex_type& m, adopt_lock_t); + +#include +#include +#include + + +int main() +{ + boost::mutex m; + m.lock(); + boost::unique_lock lk(m, boost::adopt_lock); + BOOST_TEST(lk.mutex() == &m); + BOOST_TEST(lk.owns_lock() == true); + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/locks/unique_lock/cons/copy_assign_fail.cpp b/test/sync/mutual_exclusion/locks/unique_lock/cons/copy_assign_fail.cpp new file mode 100644 index 00000000..f086d060 --- /dev/null +++ b/test/sync/mutual_exclusion/locks/unique_lock/cons/copy_assign_fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// template class unique_lock; + +// unique_lock& operator=(unique_lock const&) = delete; + +#include +#include +#include + +boost::mutex m0; +boost::mutex m1; + +int main() +{ + boost::unique_lock lk0(m0); + boost::unique_lock lk1(m1); + lk1 = lk0; + BOOST_TEST(lk1.mutex() == &m0); + BOOST_TEST(lk1.owns_lock() == true); + BOOST_TEST(lk0.mutex() == 0); + BOOST_TEST(lk0.owns_lock() == false); + +} + diff --git a/test/sync/mutual_exclusion/locks/unique_lock/cons/copy_ctor_fail.cpp b/test/sync/mutual_exclusion/locks/unique_lock/cons/copy_ctor_fail.cpp new file mode 100644 index 00000000..a5f1ef3b --- /dev/null +++ b/test/sync/mutual_exclusion/locks/unique_lock/cons/copy_ctor_fail.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// template class unique_lock; + +// unique_lock(unique_lock const&) = delete; + + +#include +#include +#include + +boost::mutex m0; +boost::mutex m1; + +int main() +{ + boost::unique_lock lk0(m0); + boost::unique_lock lk1 = lk0; + BOOST_TEST(lk1.mutex() == &m1); + BOOST_TEST(lk1.owns_lock() == true); + BOOST_TEST(lk0.mutex() == 0); + BOOST_TEST(lk0.owns_lock() == false); +} + diff --git a/test/sync/mutual_exclusion/locks/unique_lock/cons/default_pass.cpp b/test/sync/mutual_exclusion/locks/unique_lock/cons/default_pass.cpp new file mode 100644 index 00000000..409d30e8 --- /dev/null +++ b/test/sync/mutual_exclusion/locks/unique_lock/cons/default_pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// template class unique_lock; + +// unique_lock(unique_lock const&) = delete; + +#include +#include +#include + +int main() +{ + boost::unique_lock ul; + BOOST_TEST(!ul.owns_lock()); + BOOST_TEST(ul.mutex() == 0); + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/locks/unique_lock/cons/defer_lock_pass.cpp b/test/sync/mutual_exclusion/locks/unique_lock/cons/defer_lock_pass.cpp new file mode 100644 index 00000000..9aae0544 --- /dev/null +++ b/test/sync/mutual_exclusion/locks/unique_lock/cons/defer_lock_pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// template class unique_lock; + +// unique_lock(mutex_type& m, adopt_lock_t); + +#include +#include +#include + +int main() +{ + boost::mutex m; + m.lock(); + boost::unique_lock lk(m, boost::defer_lock); + BOOST_TEST(lk.mutex() == &m); + BOOST_TEST(lk.owns_lock() == false); + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/locks/unique_lock/cons/duration_pass.cpp b/test/sync/mutual_exclusion/locks/unique_lock/cons/duration_pass.cpp new file mode 100644 index 00000000..0e60d901 --- /dev/null +++ b/test/sync/mutual_exclusion/locks/unique_lock/cons/duration_pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// template class unique_lock; + +// template +// unique_lock(mutex_type& m, const chrono::duration& rel_time); + +#include +#include +#include +#include + +boost::timed_mutex m; + +typedef boost::chrono::steady_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; + +void f1() +{ + time_point t0 = Clock::now(); + boost::unique_lock lk(m, ms(300)); + BOOST_TEST(lk.owns_lock() == true); + time_point t1 = Clock::now(); + ns d = t1 - t0 - ms(250); + BOOST_TEST(d < ns(5000000)); // within 5ms +} + +void f2() +{ + time_point t0 = Clock::now(); + boost::unique_lock lk(m, ms(250)); + BOOST_TEST(lk.owns_lock() == false); + time_point t1 = Clock::now(); + ns d = t1 - t0 - ms(250); + BOOST_TEST(d < ns(5000000)); // within 5ms +} + +int main() +{ + { + m.lock(); + boost::thread t(f1); + boost::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); + } + { + m.lock(); + boost::thread t(f2); + boost::this_thread::sleep_for(ms(300)); + m.unlock(); + t.join(); + } + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/locks/unique_lock/cons/move_assign_pass.cpp b/test/sync/mutual_exclusion/locks/unique_lock/cons/move_assign_pass.cpp new file mode 100644 index 00000000..cc7fa692 --- /dev/null +++ b/test/sync/mutual_exclusion/locks/unique_lock/cons/move_assign_pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// template class unique_lock; + +// unique_lock(unique_lock const&) = delete; + + +#include +#include +#include + +boost::mutex m0; +boost::mutex m1; + +int main() +{ + boost::unique_lock lk0(m0); + boost::unique_lock lk1(m1); + lk1 = boost::move(lk0); + BOOST_TEST(lk1.mutex() == &m0); + BOOST_TEST(lk1.owns_lock() == true); + BOOST_TEST(lk0.mutex() == 0); + BOOST_TEST(lk0.owns_lock() == false); + + return boost::report_errors(); + +} + diff --git a/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_pass.cpp b/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_pass.cpp new file mode 100644 index 00000000..cc841fbc --- /dev/null +++ b/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// template class unique_lock; + +// unique_lock& operator=(unique_lock&& u); + + +#include +#include +#include + +boost::mutex m; + +int main() +{ + boost::unique_lock lk0(m); + boost::unique_lock lk( (boost::move(lk0))); + BOOST_TEST(lk.mutex() == &m); + BOOST_TEST(lk.owns_lock() == true); + BOOST_TEST(lk0.mutex() == 0); + BOOST_TEST(lk0.owns_lock() == false); + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/locks/unique_lock/cons/mutex_pass.cpp b/test/sync/mutual_exclusion/locks/unique_lock/cons/mutex_pass.cpp new file mode 100644 index 00000000..bfa56696 --- /dev/null +++ b/test/sync/mutual_exclusion/locks/unique_lock/cons/mutex_pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// template class unique_lock; + +// explicit unique_lock(Mutex& m); + + +#include +#include +#include +#include + +boost::mutex m; + +typedef boost::chrono::system_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; + +void f() +{ + time_point t0 = Clock::now(); + time_point t1; + { + boost::unique_lock ul(m); + t1 = Clock::now(); + } + ns d = t1 - t0 - ms(250); + BOOST_TEST(d < ns(2500000)); // within 2.5ms +} + +int main() +{ + m.lock(); + boost::thread t(f); + boost::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/locks/unique_lock/cons/time_point_pass.cpp b/test/sync/mutual_exclusion/locks/unique_lock/cons/time_point_pass.cpp new file mode 100644 index 00000000..b40923db --- /dev/null +++ b/test/sync/mutual_exclusion/locks/unique_lock/cons/time_point_pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// template class unique_lock; + +// template +// unique_lock(mutex_type& m, const chrono::time_point& abs_time); + +#include +#include +#include +#include + +boost::timed_mutex m; + +typedef boost::chrono::steady_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; + +void f1() +{ + time_point t0 = Clock::now(); + boost::unique_lock lk(m, Clock::now() + ms(300)); + BOOST_TEST(lk.owns_lock() == true); + time_point t1 = Clock::now(); + ns d = t1 - t0 - ms(250); + BOOST_TEST(d < ns(50000000)); // within 50ms +} + +void f2() +{ + time_point t0 = Clock::now(); + boost::unique_lock lk(m, Clock::now() + ms(250)); + BOOST_TEST(lk.owns_lock() == false); + time_point t1 = Clock::now(); + ns d = t1 - t0 - ms(250); + BOOST_TEST(d < ns(5000000)); // within 5ms +} + +int main() +{ + { + m.lock(); + boost::thread t(f1); + boost::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); + } + { + m.lock(); + boost::thread t(f2); + boost::this_thread::sleep_for(ms(300)); + m.unlock(); + t.join(); + } + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/locks/unique_lock/cons/try_to_lock_pass.cpp b/test/sync/mutual_exclusion/locks/unique_lock/cons/try_to_lock_pass.cpp new file mode 100644 index 00000000..c3f8a7ce --- /dev/null +++ b/test/sync/mutual_exclusion/locks/unique_lock/cons/try_to_lock_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) + +// + +// template class unique_lock; + +// unique_lock(mutex_type& m, try_to_lock_t); + + +#include +#include +#include +#include + +boost::mutex m; + +typedef boost::chrono::system_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; + +void f() +{ + time_point t0 = Clock::now(); + { + boost::unique_lock lk(m, boost::try_to_lock); + BOOST_TEST(lk.owns_lock() == false); + } + { + boost::unique_lock lk(m, boost::try_to_lock); + BOOST_TEST(lk.owns_lock() == false); + } + { + boost::unique_lock lk(m, boost::try_to_lock); + BOOST_TEST(lk.owns_lock() == false); + } + while (true) + { + boost::unique_lock lk(m, boost::try_to_lock); + if (lk.owns_lock()) break; + } + time_point t1 = Clock::now(); + m.unlock(); + ns d = t1 - t0 - ms(250); + BOOST_TEST(d < ns(50000000)); // within 50ms +} + +int main() +{ + m.lock(); + boost::thread t(f); + boost::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/locks/unique_lock/locking/lock_pass.cpp b/test/sync/mutual_exclusion/locks/unique_lock/locking/lock_pass.cpp new file mode 100644 index 00000000..5676b35c --- /dev/null +++ b/test/sync/mutual_exclusion/locks/unique_lock/locking/lock_pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// template class unique_lock; + +// void lock(); + +#include +#include +#include +#include +#include + +boost::mutex m; + +typedef boost::chrono::system_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; + +void f() +{ + boost::unique_lock < boost::mutex > lk(m, boost::defer_lock); + time_point t0 = Clock::now(); + lk.lock(); + time_point t1 = Clock::now(); + BOOST_TEST(lk.owns_lock() == true); + ns d = t1 - t0 - ms(250); + BOOST_TEST(d < ns(2500000)); // within 2.5ms + try + { + lk.lock(); + BOOST_TEST(false); + } + catch (boost::system::system_error& e) + { + BOOST_TEST(e.code().value() == boost::system::errc::resource_deadlock_would_occur); + } + lk.unlock(); + lk.release(); + try + { + lk.lock(); + BOOST_TEST(false); + } + catch (boost::system::system_error& e) + { + BOOST_TEST(e.code().value() == boost::system::errc::operation_not_permitted); + } +} + +int main() +{ + m.lock(); + boost::thread t(f); + boost::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/locks/unique_lock/locking/try_lock_for_pass.cpp b/test/sync/mutual_exclusion/locks/unique_lock/locking/try_lock_for_pass.cpp new file mode 100644 index 00000000..c099fd6b --- /dev/null +++ b/test/sync/mutual_exclusion/locks/unique_lock/locking/try_lock_for_pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// template class unique_lock; + +// template +// bool try_lock_for(const chrono::duration& rel_time); + +#include +//#include +#include + +bool try_lock_for_called = false; + +typedef boost::chrono::milliseconds ms; + +struct mutex +{ + template + bool try_lock_for(const boost::chrono::duration& rel_time) + { + BOOST_TEST(rel_time == ms(5)); + try_lock_for_called = !try_lock_for_called; + return try_lock_for_called; + } + void unlock() + { + } +}; + +mutex m; + +int main() +{ + boost::unique_lock lk(m, boost::defer_lock); + BOOST_TEST(lk.try_lock_for(ms(5)) == true); + BOOST_TEST(try_lock_for_called == true); + BOOST_TEST(lk.owns_lock() == true); + try + { + lk.try_lock_for(ms(5)); + BOOST_TEST(false); + } + catch (boost::system::system_error& e) + { + BOOST_TEST(e.code().value() == boost::system::errc::resource_deadlock_would_occur); + } + lk.unlock(); + BOOST_TEST(lk.try_lock_for(ms(5)) == false); + BOOST_TEST(try_lock_for_called == false); + BOOST_TEST(lk.owns_lock() == false); + lk.release(); + try + { + lk.try_lock_for(ms(5)); + BOOST_TEST(false); + } + catch (boost::system::system_error& e) + { + BOOST_TEST(e.code().value() == boost::system::errc::operation_not_permitted); + } + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/locks/unique_lock/locking/try_lock_pass.cpp b/test/sync/mutual_exclusion/locks/unique_lock/locking/try_lock_pass.cpp new file mode 100644 index 00000000..61e75b93 --- /dev/null +++ b/test/sync/mutual_exclusion/locks/unique_lock/locking/try_lock_pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// template class unique_lock; + +// template +// bool try_lock_for(const chrono::duration& rel_time); + +#include +//#include +#include + +bool try_lock_called = false; + +struct mutex +{ + bool try_lock() + { + try_lock_called = !try_lock_called; + return try_lock_called; + } + void unlock() + { + } +}; + +mutex m; + +int main() +{ + boost::unique_lock lk(m, boost::defer_lock); + BOOST_TEST(lk.try_lock() == true); + BOOST_TEST(try_lock_called == true); + BOOST_TEST(lk.owns_lock() == true); + try + { + lk.try_lock(); + BOOST_TEST(false); + } + catch (boost::system::system_error& e) + { + BOOST_TEST(e.code().value() == boost::system::errc::resource_deadlock_would_occur); + } + lk.unlock(); + BOOST_TEST(lk.try_lock() == false); + BOOST_TEST(try_lock_called == false); + BOOST_TEST(lk.owns_lock() == false); + lk.release(); + try + { + lk.try_lock(); + BOOST_TEST(false); + } + catch (boost::system::system_error& e) + { + BOOST_TEST(e.code().value() == boost::system::errc::operation_not_permitted); + } + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/locks/unique_lock/locking/try_lock_until_pass.cpp b/test/sync/mutual_exclusion/locks/unique_lock/locking/try_lock_until_pass.cpp new file mode 100644 index 00000000..50deaf2d --- /dev/null +++ b/test/sync/mutual_exclusion/locks/unique_lock/locking/try_lock_until_pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// template class unique_lock; + +// template +// bool try_lock_until(const chrono::time_point& abs_time); + +#include +#include +#include + +bool try_lock_until_called = false; + +struct mutex +{ + template + bool try_lock_until(const boost::chrono::time_point& abs_time) + { + typedef boost::chrono::milliseconds ms; + BOOST_TEST(Clock::now() - abs_time < ms(5)); + try_lock_until_called = !try_lock_until_called; + return try_lock_until_called; + } + void unlock() + { + } +}; + +mutex m; + +int main() +{ + typedef boost::chrono::steady_clock Clock; + boost::unique_lock lk(m, boost::defer_lock); + BOOST_TEST(lk.try_lock_until(Clock::now()) == true); + BOOST_TEST(try_lock_until_called == true); + BOOST_TEST(lk.owns_lock() == true); + try + { + lk.try_lock_until(Clock::now()); + BOOST_TEST(false); + } + catch (boost::system::system_error& e) + { + BOOST_TEST(e.code().value() == boost::system::errc::resource_deadlock_would_occur); + } + lk.unlock(); + BOOST_TEST(lk.try_lock_until(Clock::now()) == false); + BOOST_TEST(try_lock_until_called == false); + BOOST_TEST(lk.owns_lock() == false); + lk.release(); + try + { + lk.try_lock_until(Clock::now()); + BOOST_TEST(false); + } + catch (boost::system::system_error& e) + { + BOOST_TEST(e.code().value() == boost::system::errc::operation_not_permitted); + } + return boost::report_errors(); +} diff --git a/test/sync/mutual_exclusion/locks/unique_lock/locking/unlock_pass.cpp b/test/sync/mutual_exclusion/locks/unique_lock/locking/unlock_pass.cpp new file mode 100644 index 00000000..30e4de89 --- /dev/null +++ b/test/sync/mutual_exclusion/locks/unique_lock/locking/unlock_pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// template class unique_lock; + +// template +// bool try_lock_for(const chrono::duration& rel_time); + +#include +//#include +#include + +bool unlock_called = false; + +struct mutex +{ + void lock() + { + } + void unlock() + { + unlock_called = true; + } +}; + +mutex m; + +int main() +{ + boost::unique_lock lk(m); + lk.unlock(); + BOOST_TEST(unlock_called == true); + BOOST_TEST(lk.owns_lock() == false); + try + { + lk.unlock(); + BOOST_TEST(false); + } + catch (boost::system::system_error& e) + { + BOOST_TEST(e.code().value() == boost::system::errc::operation_not_permitted); + } + lk.release(); + try + { + lk.unlock(); + BOOST_TEST(false); + } + catch (boost::system::system_error& e) + { + BOOST_TEST(e.code().value() == boost::system::errc::operation_not_permitted); + } + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/locks/unique_lock/mod/member_swap_pass.cpp b/test/sync/mutual_exclusion/locks/unique_lock/mod/member_swap_pass.cpp new file mode 100644 index 00000000..b0334907 --- /dev/null +++ b/test/sync/mutual_exclusion/locks/unique_lock/mod/member_swap_pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// template class unique_lock; + +// void swap(unique_lock& u); + +#include +#include + +struct mutex +{ + void lock() + { + } + void unlock() + { + } +}; + +mutex m; + +int main() +{ + boost::unique_lock lk1(m); + boost::unique_lock lk2; + lk1.swap(lk2); + BOOST_TEST(lk1.mutex() == 0); + BOOST_TEST(lk1.owns_lock() == false); + BOOST_TEST(lk2.mutex() == &m); + BOOST_TEST(lk2.owns_lock() == true); + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/locks/unique_lock/mod/non_member_swap_pass.cpp b/test/sync/mutual_exclusion/locks/unique_lock/mod/non_member_swap_pass.cpp new file mode 100644 index 00000000..90ec4b0d --- /dev/null +++ b/test/sync/mutual_exclusion/locks/unique_lock/mod/non_member_swap_pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// template +// void swap(unique_lock& x, unique_lock& y); + +#include +#include + +struct mutex +{ + void lock() + { + } + void unlock() + { + } +}; + +mutex m; + +int main() +{ + boost::unique_lock lk1(m); + boost::unique_lock lk2; + swap(lk1, lk2); + BOOST_TEST(lk1.mutex() == 0); + BOOST_TEST(lk1.owns_lock() == false); + BOOST_TEST(lk2.mutex() == &m); + BOOST_TEST(lk2.owns_lock() == true); + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/locks/unique_lock/mod/release_pass.cpp b/test/sync/mutual_exclusion/locks/unique_lock/mod/release_pass.cpp new file mode 100644 index 00000000..c755bc4d --- /dev/null +++ b/test/sync/mutual_exclusion/locks/unique_lock/mod/release_pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// template class unique_lock; + +// void Mutex* release(); + +#include +#include + +struct mutex +{ + static int lock_count; + static int unlock_count; + void lock() + { + ++lock_count; + } + void unlock() + { + ++unlock_count; + } +}; + +int mutex::lock_count = 0; +int mutex::unlock_count = 0; + +mutex m; + +int main() +{ + boost::unique_lock lk(m); + BOOST_TEST(lk.mutex() == &m); + BOOST_TEST(lk.owns_lock() == true); + BOOST_TEST(mutex::lock_count == 1); + BOOST_TEST(mutex::unlock_count == 0); + BOOST_TEST(lk.release() == &m); + BOOST_TEST(lk.mutex() == 0); + BOOST_TEST(lk.owns_lock() == false); + BOOST_TEST(mutex::lock_count == 1); + BOOST_TEST(mutex::unlock_count == 0); + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/locks/unique_lock/obs/mutex_pass.cpp b/test/sync/mutual_exclusion/locks/unique_lock/obs/mutex_pass.cpp new file mode 100644 index 00000000..8eb92420 --- /dev/null +++ b/test/sync/mutual_exclusion/locks/unique_lock/obs/mutex_pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// template class unique_lock; + +// Mutex *mutex() const; + +#include +#include +#include + +boost::mutex m; + +int main() +{ + boost::unique_lock lk0; + BOOST_TEST(lk0.mutex() == 0); + boost::unique_lock lk1(m); + BOOST_TEST(lk1.mutex() == &m); + lk1.unlock(); + BOOST_TEST(lk1.mutex() == &m); + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/locks/unique_lock/obs/op_bool_pass.cpp b/test/sync/mutual_exclusion/locks/unique_lock/obs/op_bool_pass.cpp new file mode 100644 index 00000000..47f53b5b --- /dev/null +++ b/test/sync/mutual_exclusion/locks/unique_lock/obs/op_bool_pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// template class unique_lock; + +// explicit operator bool() const; + +#include +#include +#include + +boost::mutex m; + +int main() +{ + boost::unique_lock < boost::mutex > lk0; + BOOST_TEST(bool(lk0) == false); + boost::unique_lock < boost::mutex > lk1(m); + BOOST_TEST(bool(lk1) == true); + lk1.unlock(); + BOOST_TEST(bool(lk1) == false); + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/locks/unique_lock/obs/owns_lock_pass.cpp b/test/sync/mutual_exclusion/locks/unique_lock/obs/owns_lock_pass.cpp new file mode 100644 index 00000000..6a78db9c --- /dev/null +++ b/test/sync/mutual_exclusion/locks/unique_lock/obs/owns_lock_pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// template class unique_lock; + +// bool owns_lock() const; + +#include +#include +#include + +boost::mutex m; + +int main() +{ + boost::unique_lock lk0; + BOOST_TEST(lk0.owns_lock() == false); + boost::unique_lock lk1(m); + BOOST_TEST(lk1.owns_lock() == true); + lk1.unlock(); + BOOST_TEST(lk1.owns_lock() == false); + + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/locks/unique_lock/types_pass.cpp b/test/sync/mutual_exclusion/locks/unique_lock/types_pass.cpp new file mode 100644 index 00000000..f6581fdc --- /dev/null +++ b/test/sync/mutual_exclusion/locks/unique_lock/types_pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// + +// struct defer_lock_t {}; +// struct try_to_lock_t {}; +// struct adopt_lock_t {}; +// +// constexpr defer_lock_t defer_lock{}; +// constexpr try_to_lock_t try_to_lock{}; +// constexpr adopt_lock_t adopt_lock{}; + +#include +#include + +int main() +{ + typedef boost::defer_lock_t T1; + typedef boost::try_to_lock_t T2; + typedef boost::adopt_lock_t T3; + + T1 t1 = boost::defer_lock; + T2 t2 = boost::try_to_lock; + T3 t3 = boost::adopt_lock; + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/mutex/assign_fail.cpp b/test/sync/mutual_exclusion/mutex/assign_fail.cpp new file mode 100644 index 00000000..8ad27da6 --- /dev/null +++ b/test/sync/mutual_exclusion/mutex/assign_fail.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class mutex; + +// mutex& operator=(const mutex&) = delete; + +#include +#include + +int main() +{ + boost::mutex m0; + boost::mutex m1(m0); +} + diff --git a/test/sync/mutual_exclusion/mutex/copy_fail.cpp b/test/sync/mutual_exclusion/mutex/copy_fail.cpp new file mode 100644 index 00000000..c9cd3661 --- /dev/null +++ b/test/sync/mutual_exclusion/mutex/copy_fail.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class mutex; + +// mutex(const mutex&) = delete; + +#include +#include + +int main() +{ + boost::mutex m0; + boost::mutex m1(m0); +} + diff --git a/test/sync/mutual_exclusion/mutex/default_pass.cpp b/test/sync/mutual_exclusion/mutex/default_pass.cpp new file mode 100644 index 00000000..a911eefc --- /dev/null +++ b/test/sync/mutual_exclusion/mutex/default_pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class mutex; + +// mutex(); + +#include +#include + +int main() +{ + boost::mutex m0; + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/mutex/lock_pass.cpp b/test/sync/mutual_exclusion/mutex/lock_pass.cpp new file mode 100644 index 00000000..f0282c78 --- /dev/null +++ b/test/sync/mutual_exclusion/mutex/lock_pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class mutex; + +// void lock(); + +#include +#include +#include + +boost::mutex m; + +typedef boost::chrono::system_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; + +void f() +{ + time_point t0 = Clock::now(); + m.lock(); + time_point t1 = Clock::now(); + m.unlock(); + ns d = t1 - t0 - ms(250); + BOOST_TEST(d < ns(2500000)); // within 2.5ms +} + +int main() +{ + m.lock(); + boost::thread t(f); + boost::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/mutex/native_handle_pass.cpp b/test/sync/mutual_exclusion/mutex/native_handle_pass.cpp new file mode 100644 index 00000000..e605749a --- /dev/null +++ b/test/sync/mutual_exclusion/mutex/native_handle_pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class mutex; + +// typedef pthread_mutex_t* native_handle_type; +// native_handle_type native_handle(); + +#include +#include + +int main() +{ + boost::mutex m; + boost::mutex::native_handle_type h = m.native_handle(); + BOOST_TEST(h); + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/mutex/try_lock_pass.cpp b/test/sync/mutual_exclusion/mutex/try_lock_pass.cpp new file mode 100644 index 00000000..6596cf97 --- /dev/null +++ b/test/sync/mutual_exclusion/mutex/try_lock_pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class mutex; + +// bool try_lock(); + +#include +#include +#include + +boost::mutex m; + +typedef boost::chrono::system_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; + +void f() +{ + time_point t0 = Clock::now(); + BOOST_TEST(!m.try_lock()); + BOOST_TEST(!m.try_lock()); + BOOST_TEST(!m.try_lock()); + while (!m.try_lock()) + ; + time_point t1 = Clock::now(); + m.unlock(); + ns d = t1 - t0 - ms(250); + BOOST_TEST(d < ns(50000000)); // within 50ms +} + +int main() +{ + m.lock(); + boost::thread t(f); + boost::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/recursive_mutex/assign_fail.cpp b/test/sync/mutual_exclusion/recursive_mutex/assign_fail.cpp new file mode 100644 index 00000000..164c89b9 --- /dev/null +++ b/test/sync/mutual_exclusion/recursive_mutex/assign_fail.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class recursive_mutex; + +// recursive_mutex& operator=(const recursive_mutex&) = delete; + +#include +#include + +int main() +{ + boost::recursive_mutex m0; + boost::recursive_mutex m1(m0); +} + diff --git a/test/sync/mutual_exclusion/recursive_mutex/copy_fail.cpp b/test/sync/mutual_exclusion/recursive_mutex/copy_fail.cpp new file mode 100644 index 00000000..e2d74769 --- /dev/null +++ b/test/sync/mutual_exclusion/recursive_mutex/copy_fail.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class recursive_mutex; + +// recursive_mutex(const recursive_mutex&) = delete; + +#include +#include + +int main() +{ + boost::recursive_mutex m0; + boost::recursive_mutex m1(m0); +} + diff --git a/test/sync/mutual_exclusion/recursive_mutex/default_pass.cpp b/test/sync/mutual_exclusion/recursive_mutex/default_pass.cpp new file mode 100644 index 00000000..6b619972 --- /dev/null +++ b/test/sync/mutual_exclusion/recursive_mutex/default_pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class recursive_mutex; + +// recursive_mutex(); + +#include +#include + +int main() +{ + boost::recursive_mutex m0; + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/recursive_mutex/lock_pass.cpp b/test/sync/mutual_exclusion/recursive_mutex/lock_pass.cpp new file mode 100644 index 00000000..dd243524 --- /dev/null +++ b/test/sync/mutual_exclusion/recursive_mutex/lock_pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class recursive_mutex; + +// void lock(); + +#include +#include +#include + +boost::recursive_mutex m; + +typedef boost::chrono::system_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; + +void f() +{ + time_point t0 = Clock::now(); + m.lock(); + time_point t1 = Clock::now(); + m.lock(); + m.unlock(); + m.unlock(); + ns d = t1 - t0 - ms(250); + assert(d < ns(2500000)); // within 2.5ms +} + +int main() +{ + m.lock(); + boost::thread t(f); + boost::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/recursive_mutex/native_handle_pass.cpp b/test/sync/mutual_exclusion/recursive_mutex/native_handle_pass.cpp new file mode 100644 index 00000000..f0638eb6 --- /dev/null +++ b/test/sync/mutual_exclusion/recursive_mutex/native_handle_pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class recursive_mutex; + +// typedef pthread_recursive_mutex_t* native_handle_type; +// native_handle_type native_handle(); + +#include +#include + +int main() +{ + boost::recursive_mutex m; + boost::recursive_mutex::native_handle_type h = m.native_handle(); + BOOST_TEST(h); + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/recursive_mutex/try_lock_pass.cpp b/test/sync/mutual_exclusion/recursive_mutex/try_lock_pass.cpp new file mode 100644 index 00000000..d018272f --- /dev/null +++ b/test/sync/mutual_exclusion/recursive_mutex/try_lock_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) + +// + +// class recursive_mutex; + +// bool try_lock(); + +#include +#include +#include + +boost::recursive_mutex m; + +typedef boost::chrono::system_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; + +void f() +{ + time_point t0 = Clock::now(); + BOOST_TEST(!m.try_lock()); + BOOST_TEST(!m.try_lock()); + BOOST_TEST(!m.try_lock()); + while (!m.try_lock()) + ; + time_point t1 = Clock::now(); + BOOST_TEST(m.try_lock()); + m.unlock(); + m.unlock(); + ns d = t1 - t0 - ms(250); + BOOST_TEST(d < ns(50000000)); // within 50ms +} + +int main() +{ + m.lock(); + boost::thread t(f); + boost::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/recursive_timed_mutex/assign_fail.cpp b/test/sync/mutual_exclusion/recursive_timed_mutex/assign_fail.cpp new file mode 100644 index 00000000..0964f806 --- /dev/null +++ b/test/sync/mutual_exclusion/recursive_timed_mutex/assign_fail.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class recursive_timed_mutex; + +// recursive_timed_mutex& operator=(const recursive_timed_mutex&) = delete; + +#include +#include + +int main() +{ + boost::recursive_timed_mutex m0; + boost::recursive_timed_mutex m1(m0); +} + diff --git a/test/sync/mutual_exclusion/recursive_timed_mutex/copy_fail.cpp b/test/sync/mutual_exclusion/recursive_timed_mutex/copy_fail.cpp new file mode 100644 index 00000000..3b27ebc1 --- /dev/null +++ b/test/sync/mutual_exclusion/recursive_timed_mutex/copy_fail.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class recursive_timed_mutex; + +// recursive_timed_mutex(const recursive_timed_mutex&) = delete; + +#include +#include + +int main() +{ + boost::recursive_timed_mutex m0; + boost::recursive_timed_mutex m1(m0); +} + diff --git a/test/sync/mutual_exclusion/recursive_timed_mutex/default_pass.cpp b/test/sync/mutual_exclusion/recursive_timed_mutex/default_pass.cpp new file mode 100644 index 00000000..1e75b7b0 --- /dev/null +++ b/test/sync/mutual_exclusion/recursive_timed_mutex/default_pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class recursive_timed_mutex; + +// recursive_timed_mutex(); + +#include +#include + +int main() +{ + boost::recursive_timed_mutex m0; + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/recursive_timed_mutex/lock_pass.cpp b/test/sync/mutual_exclusion/recursive_timed_mutex/lock_pass.cpp new file mode 100644 index 00000000..4b7ad1be --- /dev/null +++ b/test/sync/mutual_exclusion/recursive_timed_mutex/lock_pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class recursive_timed_mutex; + +// void lock(); + +#include +#include +#include + +boost::recursive_timed_mutex m; + +typedef boost::chrono::system_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; + +void f() +{ + time_point t0 = Clock::now(); + m.lock(); + time_point t1 = Clock::now(); + m.lock(); + m.unlock(); + m.unlock(); + ns d = t1 - t0 - ms(250); + assert(d < ns(2500000)); // within 2.5ms +} + +int main() +{ + m.lock(); + boost::thread t(f); + boost::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/recursive_timed_mutex/native_handle_pass.cpp b/test/sync/mutual_exclusion/recursive_timed_mutex/native_handle_pass.cpp new file mode 100644 index 00000000..4cf7db7a --- /dev/null +++ b/test/sync/mutual_exclusion/recursive_timed_mutex/native_handle_pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class recursive_timed_mutex; + +// typedef pthread_recursive_mutex_t* native_handle_type; +// native_handle_type native_handle(); + +#include +#include + +int main() +{ + boost::recursive_timed_mutex m; + boost::recursive_timed_mutex::native_handle_type h = m.native_handle(); + BOOST_TEST(h); + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/recursive_timed_mutex/try_lock_for_pass.cpp b/test/sync/mutual_exclusion/recursive_timed_mutex/try_lock_for_pass.cpp new file mode 100644 index 00000000..d7dac6be --- /dev/null +++ b/test/sync/mutual_exclusion/recursive_timed_mutex/try_lock_for_pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class recursive_timed_mutex; + +// template +// bool try_lock_for(const chrono::duration& rel_time); + +#include +#include +#include + +boost::recursive_timed_mutex m; + +typedef boost::chrono::steady_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; + +void f1() +{ + time_point t0 = Clock::now(); + BOOST_TEST(m.try_lock_for(ms(300)) == true); + time_point t1 = Clock::now(); + BOOST_TEST(m.try_lock()); + m.unlock(); + m.unlock(); + ns d = t1 - t0 - ms(250); + BOOST_TEST(d < ns(5000000)); // within 5ms +} + +void f2() +{ + time_point t0 = Clock::now(); + BOOST_TEST(m.try_lock_for(ms(250)) == false); + time_point t1 = Clock::now(); + ns d = t1 - t0 - ms(250); + BOOST_TEST(d < ns(5000000)); // within 5ms +} + +int main() +{ + { + m.lock(); + boost::thread t(f1); + boost::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); + } + { + m.lock(); + boost::thread t(f2); + boost::this_thread::sleep_for(ms(300)); + m.unlock(); + t.join(); + } + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/recursive_timed_mutex/try_lock_pass.cpp b/test/sync/mutual_exclusion/recursive_timed_mutex/try_lock_pass.cpp new file mode 100644 index 00000000..412cd57e --- /dev/null +++ b/test/sync/mutual_exclusion/recursive_timed_mutex/try_lock_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) + +// + +// class recursive_timed_mutex; + +// bool try_lock(); + +#include +#include +#include + +boost::recursive_timed_mutex m; + +typedef boost::chrono::system_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; + +void f() +{ + time_point t0 = Clock::now(); + BOOST_TEST(!m.try_lock()); + BOOST_TEST(!m.try_lock()); + BOOST_TEST(!m.try_lock()); + while (!m.try_lock()) + ; + time_point t1 = Clock::now(); + BOOST_TEST(m.try_lock()); + m.unlock(); + m.unlock(); + ns d = t1 - t0 - ms(250); + BOOST_TEST(d < ns(50000000)); // within 50ms +} + +int main() +{ + m.lock(); + boost::thread t(f); + boost::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/recursive_timed_mutex/try_lock_until_pass.cpp b/test/sync/mutual_exclusion/recursive_timed_mutex/try_lock_until_pass.cpp new file mode 100644 index 00000000..35e89685 --- /dev/null +++ b/test/sync/mutual_exclusion/recursive_timed_mutex/try_lock_until_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) + +// + +// class recursive_timed_mutex; + +// template +// bool try_lock_until(const chrono::time_point& abs_time); + +#include +#include +#include + +boost::recursive_timed_mutex m; + +typedef boost::chrono::steady_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; + +void f1() +{ + time_point t0 = Clock::now(); + BOOST_TEST(m.try_lock_until(Clock::now() + ms(300)) == true); + time_point t1 = Clock::now(); + m.unlock(); + ns d = t1 - t0 - ms(250); + BOOST_TEST(d < ns(5000000)); // within 5ms +} + +void f2() +{ + time_point t0 = Clock::now(); + BOOST_TEST(m.try_lock_until(Clock::now() + ms(250)) == false); + time_point t1 = Clock::now(); + ns d = t1 - t0 - ms(250); + BOOST_TEST(d < ns(5000000)); // within 5ms +} + +int main() +{ + { + m.lock(); + boost::thread t(f1); + boost::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); + } + { + m.lock(); + boost::thread t(f2); + boost::this_thread::sleep_for(ms(300)); + m.unlock(); + t.join(); + } + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/timed_mutex/assign_fail.cpp b/test/sync/mutual_exclusion/timed_mutex/assign_fail.cpp new file mode 100644 index 00000000..1852d159 --- /dev/null +++ b/test/sync/mutual_exclusion/timed_mutex/assign_fail.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class timed_mutex; + +// timed_mutex& operator=(const timed_mutex&) = delete; + +#include +#include + +int main() +{ + boost::timed_mutex m0; + boost::timed_mutex m1(m0); +} + diff --git a/test/sync/mutual_exclusion/timed_mutex/copy_fail.cpp b/test/sync/mutual_exclusion/timed_mutex/copy_fail.cpp new file mode 100644 index 00000000..ec839bbc --- /dev/null +++ b/test/sync/mutual_exclusion/timed_mutex/copy_fail.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class timed_mutex; + +// timed_mutex(const timed_mutex&) = delete; + +#include +#include + +int main() +{ + boost::timed_mutex m0; + boost::timed_mutex m1(m0); +} + diff --git a/test/sync/mutual_exclusion/timed_mutex/default_pass.cpp b/test/sync/mutual_exclusion/timed_mutex/default_pass.cpp new file mode 100644 index 00000000..6b7c6f2b --- /dev/null +++ b/test/sync/mutual_exclusion/timed_mutex/default_pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class timed_mutex; + +// timed_mutex(); + +#include +#include + +int main() +{ + boost::timed_mutex m0; + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/timed_mutex/lock_pass.cpp b/test/sync/mutual_exclusion/timed_mutex/lock_pass.cpp new file mode 100644 index 00000000..d671bf43 --- /dev/null +++ b/test/sync/mutual_exclusion/timed_mutex/lock_pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class timed_mutex; + +// void lock(); + +#include +#include +#include + +boost::timed_mutex m; + +typedef boost::chrono::system_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; + +void f() +{ + time_point t0 = Clock::now(); + m.lock(); + time_point t1 = Clock::now(); + m.unlock(); + ns d = t1 - t0 - ms(250); + BOOST_TEST(d < ns(2500000)); // within 2.5ms +} + +int main() +{ + m.lock(); + boost::thread t(f); + boost::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/timed_mutex/native_handle_pass.cpp b/test/sync/mutual_exclusion/timed_mutex/native_handle_pass.cpp new file mode 100644 index 00000000..561983ba --- /dev/null +++ b/test/sync/mutual_exclusion/timed_mutex/native_handle_pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class timed_mutex; + +// typedef pthread_timed_mutex_t* native_handle_type; +// native_handle_type native_handle(); + +#include +#include + + +int main() +{ + boost::timed_mutex m; + boost::timed_mutex::native_handle_type h = m.native_handle(); + BOOST_TEST(h); + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/timed_mutex/try_lock_for_pass.cpp b/test/sync/mutual_exclusion/timed_mutex/try_lock_for_pass.cpp new file mode 100644 index 00000000..40c826ab --- /dev/null +++ b/test/sync/mutual_exclusion/timed_mutex/try_lock_for_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) + +// + +// class timed_mutex; + +// template +// bool try_lock_for(const chrono::duration& rel_time); + +#include +#include +#include + +boost::timed_mutex m; + +typedef boost::chrono::steady_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; + +void f1() +{ + time_point t0 = Clock::now(); + BOOST_TEST(m.try_lock_for(ms(300)) == true); + time_point t1 = Clock::now(); + m.unlock(); + ns d = t1 - t0 - ms(250); + BOOST_TEST(d < ns(5000000)); // within 5ms +} + +void f2() +{ + time_point t0 = Clock::now(); + BOOST_TEST(m.try_lock_for(ms(250)) == false); + time_point t1 = Clock::now(); + ns d = t1 - t0 - ms(250); + BOOST_TEST(d < ns(5000000)); // within 5ms +} + +int main() +{ + { + m.lock(); + boost::thread t(f1); + boost::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); + } + { + m.lock(); + boost::thread t(f2); + boost::this_thread::sleep_for(ms(300)); + m.unlock(); + t.join(); + } + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/timed_mutex/try_lock_pass.cpp b/test/sync/mutual_exclusion/timed_mutex/try_lock_pass.cpp new file mode 100644 index 00000000..c5f5455e --- /dev/null +++ b/test/sync/mutual_exclusion/timed_mutex/try_lock_pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class timed_mutex; + +// bool try_lock(); + +#include +#include +#include + +boost::timed_mutex m; + +typedef boost::chrono::system_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; + +void f() +{ + time_point t0 = Clock::now(); + BOOST_TEST(!m.try_lock()); + BOOST_TEST(!m.try_lock()); + BOOST_TEST(!m.try_lock()); + while (!m.try_lock()) + ; + time_point t1 = Clock::now(); + m.unlock(); + ns d = t1 - t0 - ms(250); + BOOST_TEST(d < ns(50000000)); // within 50ms +} + +int main() +{ + m.lock(); + boost::thread t(f); + boost::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); + + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/timed_mutex/try_lock_until_pass.cpp b/test/sync/mutual_exclusion/timed_mutex/try_lock_until_pass.cpp new file mode 100644 index 00000000..b087385c --- /dev/null +++ b/test/sync/mutual_exclusion/timed_mutex/try_lock_until_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) + +// + +// class timed_mutex; + +// template +// bool try_lock_until(const chrono::time_point& abs_time); + +#include +#include +#include + +boost::timed_mutex m; + +typedef boost::chrono::steady_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef boost::chrono::milliseconds ms; +typedef boost::chrono::nanoseconds ns; + +void f1() +{ + time_point t0 = Clock::now(); + BOOST_TEST(m.try_lock_until(Clock::now() + ms(300)) == true); + time_point t1 = Clock::now(); + m.unlock(); + ns d = t1 - t0 - ms(250); + BOOST_TEST(d < ns(5000000)); // within 5ms +} + +void f2() +{ + time_point t0 = Clock::now(); + BOOST_TEST(m.try_lock_until(Clock::now() + ms(250)) == false); + time_point t1 = Clock::now(); + ns d = t1 - t0 - ms(250); + BOOST_TEST(d < ns(5000000)); // within 5ms +} + +int main() +{ + { + m.lock(); + boost::thread t(f1); + boost::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); + } + { + m.lock(); + boost::thread t(f2); + boost::this_thread::sleep_for(ms(300)); + m.unlock(); + t.join(); + } + + return boost::report_errors(); +} + diff --git a/test/threads/this_thread/get_id/get_id_pass.cpp b/test/threads/this_thread/get_id/get_id_pass.cpp new file mode 100644 index 00000000..8fb82b4a --- /dev/null +++ b/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) + +// + +// thread::id this_thread::get_id(); + +#include + +#include + +int main() +{ + boost::thread::id id = boost::this_thread::get_id(); + BOOST_TEST(id != boost::thread::id()); + return boost::report_errors(); +} + diff --git a/test/threads/this_thread/sleep_for/sleep_for_pass.cpp b/test/threads/this_thread/sleep_for/sleep_for_pass.cpp new file mode 100644 index 00000000..a85cb11f --- /dev/null +++ b/test/threads/this_thread/sleep_for/sleep_for_pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// thread::id this_thread::get_id(); + +#include +#include + +#include + +int main() +{ + 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_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 + BOOST_TEST(std::abs(ns.count()) < err.count()); + +} + diff --git a/test/threads/this_thread/sleep_until/sleep_until_pass.cpp b/test/threads/this_thread/sleep_until/sleep_until_pass.cpp new file mode 100644 index 00000000..cb9a119d --- /dev/null +++ b/test/threads/this_thread/sleep_until/sleep_until_pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// thread::id this_thread::get_id(); + +#include +#include + +#include + +int main() +{ + 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 + BOOST_TEST(std::abs(ns.count()) < err.count()); + +} + diff --git a/test/threads/thread/assign/copy_fail.cpp b/test/threads/thread/assign/copy_fail.cpp new file mode 100644 index 00000000..98fcc87a --- /dev/null +++ b/test/threads/thread/assign/copy_fail.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class thread + +// thread& operator=(thread&& t); + +#include +#include +#include +#include + +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; + } +} + diff --git a/test/threads/thread/assign/move_pass.cpp b/test/threads/thread/assign/move_pass.cpp new file mode 100644 index 00000000..eb79e161 --- /dev/null +++ b/test/threads/thread/assign/move_pass.cpp @@ -0,0 +1,100 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class thread + +// thread& operator=(thread&& t); + +#include +#include +#include +#include +#include + +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(0); +} + +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::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::move(t1); + BOOST_TEST(false); + } + return boost::report_errors(); +} + diff --git a/test/threads/thread/constr/F_pass.cpp b/test/threads/thread/constr/F_pass.cpp new file mode 100644 index 00000000..3cd0a2a2 --- /dev/null +++ b/test/threads/thread/constr/F_pass.cpp @@ -0,0 +1,147 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class thread + +// template thread(F f, Args... args); + +#include +#include +#include +#include +#include + +unsigned throw_one = 0xFFFF; + +void* operator new(std::size_t s) throw (std::bad_alloc) +{ + if (throw_one == 0) throw std::bad_alloc(); + --throw_one; + return std::malloc(s); +} + +void operator delete(void* p) throw () +{ + 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; + } + + 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::thread t(f); + t.join(); + BOOST_TEST(f_run == true); + } + f_run = false; + { + try + { + throw_one = 0; + boost::thread t(f); + BOOST_TEST(false); + } + catch (...) + { + throw_one = 0xFFFF; + BOOST_TEST(!f_run); + } + } + { + 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); + } + 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); + BOOST_TEST(!G::op_run); + } + } + { + BOOST_TEST(G::n_alive == 0); + BOOST_TEST(!G::op_run); + boost::thread t(G(), 5, 5.5); + t.join(); + BOOST_TEST(G::n_alive == 0); + BOOST_TEST(G::op_run); + } + + return boost::report_errors(); +} diff --git a/test/threads/thread/constr/FrvalueArgs_pass.cpp b/test/threads/thread/constr/FrvalueArgs_pass.cpp new file mode 100644 index 00000000..7177e048 --- /dev/null +++ b/test/threads/thread/constr/FrvalueArgs_pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class thread + +// template thread(F&& f, Args&&... args); + +#include +#include +#include +#include +#include + +class MoveOnly +{ + MoveOnly(const MoveOnly&); +public: + MoveOnly() + { + } +#ifndef BOOST_NO_RVALUE_REFERENCES + MoveOnly(MoveOnly&&) + {} + void operator()(MoveOnly&&) + { + } +#else + MoveOnly(detail::thread_move_t) + {} + void operator()(detail::thread_move_t) + { + } +#endif + +}; + +int main() +{ + { + boost::thread t = boost::thread(MoveOnly(), MoveOnly()); + t.join(); + } + return boost::report_errors(); +} diff --git a/test/threads/thread/constr/Frvalue_pass.cpp b/test/threads/thread/constr/Frvalue_pass.cpp new file mode 100644 index 00000000..7007732c --- /dev/null +++ b/test/threads/thread/constr/Frvalue_pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class thread + +// template thread(F&& f, Args&&... args); + +#include +#include +#include +#include +#include + +class MoveOnly +{ + MoveOnly(const MoveOnly&); +public: + MoveOnly() + { + } +#ifndef BOOST_NO_RVALUE_REFERENCES + MoveOnly(MoveOnly&&) + {} +#else + MoveOnly(detail::thread_move_t) + {} +#endif + + void operator()() + { + } +}; + +int main() +{ + { + boost::thread t = boost::thread(MoveOnly()); + t.join(); + } + return boost::report_errors(); +} diff --git a/test/threads/thread/constr/copy_fail.cpp b/test/threads/thread/constr/copy_fail.cpp new file mode 100644 index 00000000..e4633285 --- /dev/null +++ b/test/threads/thread/constr/copy_fail.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class thread + +// thread(const thread&) = delete; + +#include +#include +#include +#include + +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); + } +} diff --git a/test/threads/thread/constr/default_pass.cpp b/test/threads/thread/constr/default_pass.cpp new file mode 100644 index 00000000..9270e89c --- /dev/null +++ b/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) + +// + +// class thread + +// thread(); + +#include +#include +#include + +int main() +{ + boost::thread t; + BOOST_TEST(t.get_id() == boost::thread::id()); + return boost::report_errors(); +} diff --git a/test/threads/thread/constr/move_pass.cpp b/test/threads/thread/constr/move_pass.cpp new file mode 100644 index 00000000..5e79be18 --- /dev/null +++ b/test/threads/thread/constr/move_pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class thread + +// thread(thread&& t); + +#include +#include +#include +#include + +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((boost::move(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); + } + return boost::report_errors(); +} diff --git a/test/threads/thread/destr/dtor_pass.cpp b/test/threads/thread/destr/dtor_pass.cpp new file mode 100644 index 00000000..aad2416e --- /dev/null +++ b/test/threads/thread/destr/dtor_pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class thread + +// ~thread(); + +#include +#include +#include +#include + +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(0); +} + +int main() +{ + std::set_terminate(f1); + { + BOOST_TEST(G::n_alive == 0); + BOOST_TEST(!G::op_run); + boost::thread t( (G())); + boost::this_thread::sleep_for(boost::chrono::milliseconds(250)); + //boost::this_thread::sleep(boost::posix_time::milliseconds(250)); + + } + BOOST_TEST(false); + return boost::report_errors(); +} + diff --git a/test/threads/thread/id/hash_pass.cpp b/test/threads/thread/id/hash_pass.cpp new file mode 100644 index 00000000..5202d46b --- /dev/null +++ b/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) + +// + +// + +// template +// struct hash +// : public unary_function +// { +// size_t operator()(T val) const; +// }; + + +#include +#include + +int main() +{ + { + boost::thread::id id1; + boost::thread::id id2 = boost::this_thread::get_id(); + typedef boost::hash H; + H h; + BOOST_TEST(h(id1) != h(id2)); + } + return boost::report_errors(); +} + diff --git a/test/threads/thread/members/detach_pass.cpp b/test/threads/thread/members/detach_pass.cpp new file mode 100644 index 00000000..d9369291 --- /dev/null +++ b/test/threads/thread/members/detach_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) + +// + +// class thread + +// void detach(); + +#include +#include +#include +#include +#include + +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()); + boost::this_thread::sleep_for(boost::chrono::milliseconds(250)); + BOOST_TEST(G::op_run); + BOOST_TEST(G::n_alive == 0); + } + return boost::report_errors(); +} + diff --git a/test/threads/thread/members/get_id_pass.cpp b/test/threads/thread/members/get_id_pass.cpp new file mode 100644 index 00000000..0e86a73d --- /dev/null +++ b/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) + +// + +// class thread + +// id get_id() const; + +#include +#include +#include +#include +#include + +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/test/threads/thread/members/join_pass.cpp b/test/threads/thread/members/join_pass.cpp new file mode 100644 index 00000000..d3a370a4 --- /dev/null +++ b/test/threads/thread/members/join_pass.cpp @@ -0,0 +1,130 @@ +//===----------------------------------------------------------------------===// +// +// 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) + +// + +// class thread + +// void join(); + +#include +#include +#include +#include +#include +#include +#include +#include + +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; +boost::mutex resource_deadlock_would_occur_mtx; +void resource_deadlock_would_occur_tester() +{ + try + { + boost::unique_lock 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); + } +} + +int main() +{ + { + boost::thread t0( (G())); + BOOST_TEST(t0.joinable()); + t0.join(); + BOOST_TEST(!t0.joinable()); + } + { + boost::unique_lock 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(); + 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::no_such_process); +// } +// } +// { +// boost::thread t0( (G())); +// BOOST_TEST(t0.joinable()); +// t0.join(); +// BOOST_TEST(!t0.joinable()); +// 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/test/threads/thread/members/joinable_pass.cpp b/test/threads/thread/members/joinable_pass.cpp new file mode 100644 index 00000000..60a6db76 --- /dev/null +++ b/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) + +// + +// class thread + +// bool joinable() const; + +#include +#include +#include +#include +#include + +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/test/threads/thread/members/native_handle_pass.cpp b/test/threads/thread/members/native_handle_pass.cpp new file mode 100644 index 00000000..1872945e --- /dev/null +++ b/test/threads/thread/members/native_handle_pass.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) + +// + +// class thread + +// native_handle_type native_handle(); + +#include +#include +#include +#include +#include + +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 = t0.native_handle(); + t0.join(); + } + + return boost::report_errors(); +} + diff --git a/test/threads/thread/members/swap_pass.cpp b/test/threads/thread/members/swap_pass.cpp new file mode 100644 index 00000000..688cf667 --- /dev/null +++ b/test/threads/thread/members/swap_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) + +// + +// class thread + +// native_handle_type native_handle(); + +#include +#include +#include + +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(); + t0.swap(t1); + BOOST_TEST(t0.get_id() == id1); + BOOST_TEST(t1.get_id() == id0); + t1.join(); + } +} + diff --git a/test/threads/thread/non_members/swap_pass.cpp b/test/threads/thread/non_members/swap_pass.cpp new file mode 100644 index 00000000..dd05d61e --- /dev/null +++ b/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) + +// + +// void swap(thread& x, thread& y); + +#include +#include +#include +#include +#include + +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/test/threads/thread/static/hardware_concurrency_pass.cpp b/test/threads/thread/static/hardware_concurrency_pass.cpp new file mode 100644 index 00000000..7d1581b5 --- /dev/null +++ b/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) + +// + +// class thread + +// static unsigned hardware_concurrency(); + +#include +#include + +int main() +{ + BOOST_TEST(boost::thread::hardware_concurrency() > 0); + return boost::report_errors(); +} +