| 1 | // Copyright (C) 2001-2003
|
|---|
| 2 | // William E. Kempf
|
|---|
| 3 | // Copyright (C) 2008 Anthony Williams
|
|---|
| 4 | // Copyright (C) 2008 Vicente J. Botet Escriba
|
|---|
| 5 | //
|
|---|
| 6 | // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|---|
| 7 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|---|
| 8 |
|
|---|
| 9 | #include <boost/thread/detail/config.hpp>
|
|---|
| 10 |
|
|---|
| 11 | #include <boost/thread/thread.hpp>
|
|---|
| 12 | #include <boost/thread/xtime.hpp>
|
|---|
| 13 | #include <boost/bind.hpp>
|
|---|
| 14 | #include <boost/ref.hpp>
|
|---|
| 15 | #include <boost/utility.hpp>
|
|---|
| 16 |
|
|---|
| 17 | #include <boost/test/unit_test.hpp>
|
|---|
| 18 |
|
|---|
| 19 | #define DEFAULT_EXECUTION_MONITOR_TYPE execution_monitor::use_sleep_only
|
|---|
| 20 | #include <libs/thread/test/util.inl>
|
|---|
| 21 |
|
|---|
| 22 | int test_value;
|
|---|
| 23 |
|
|---|
| 24 | void simple_thread()
|
|---|
| 25 | {
|
|---|
| 26 | test_value = 999;
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 | void test_native_handle()
|
|---|
| 31 | {
|
|---|
| 32 | boost::thread_attributes attrs;
|
|---|
| 33 |
|
|---|
| 34 | boost::thread_attributes::native_handle_type h = attrs.native_handle();
|
|---|
| 35 | #if defined(BOOST_THREAD_PLATFORM_WIN32)
|
|---|
| 36 | // ... window version
|
|---|
| 37 | #elif defined(BOOST_THREAD_PLATFORM_PTHREAD)
|
|---|
| 38 | BOOST_CHECK(!pthread_attr_setstacksize(&h, 1000000));
|
|---|
| 39 | std::size_t res;
|
|---|
| 40 | BOOST_CHECK(!pthread_attr_getstacksize(&h, &res));
|
|---|
| 41 | BOOST_CHECK(res==1000000);
|
|---|
| 42 | #else
|
|---|
| 43 | #error "Boost thread unavailable on this platform"
|
|---|
| 44 | #endif
|
|---|
| 45 |
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | void test_stack_size()
|
|---|
| 49 | {
|
|---|
| 50 | boost::thread_attributes attrs;
|
|---|
| 51 |
|
|---|
| 52 | attrs.set_stack_size(1000000u);
|
|---|
| 53 | BOOST_CHECK_EQUAL(attrs.get_stack_size(), 1000000u);
|
|---|
| 54 |
|
|---|
| 55 | }
|
|---|
| 56 | void do_test_creation_with_attrs()
|
|---|
| 57 | {
|
|---|
| 58 | test_value = 0;
|
|---|
| 59 | boost::thread_attributes attrs;
|
|---|
| 60 | attrs.set_stack_size(1000000);
|
|---|
| 61 | boost::thread thrd(attrs, &simple_thread);
|
|---|
| 62 | thrd.join();
|
|---|
| 63 | BOOST_CHECK_EQUAL(test_value, 999);
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | void test_creation_with_attrs()
|
|---|
| 67 | {
|
|---|
| 68 | timed_test(&do_test_creation_with_attrs, 1);
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 | boost::unit_test_framework::test_suite* init_unit_test_suite(int, char*[])
|
|---|
| 73 | {
|
|---|
| 74 | boost::unit_test_framework::test_suite* test =
|
|---|
| 75 | BOOST_TEST_SUITE("Boost.Threads: thread attributes test suite");
|
|---|
| 76 |
|
|---|
| 77 | test->add(BOOST_TEST_CASE(test_native_handle));
|
|---|
| 78 | test->add(BOOST_TEST_CASE(test_stack_size));
|
|---|
| 79 | test->add(BOOST_TEST_CASE(test_creation_with_attrs));
|
|---|
| 80 |
|
|---|
| 81 | return test;
|
|---|
| 82 | }
|
|---|