// Copyright (C) 2001-2003 // William E. Kempf // Copyright (C) 2008 Anthony Williams // Copyright (C) 2008 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) #include #include #include #include #include #include #include #define DEFAULT_EXECUTION_MONITOR_TYPE execution_monitor::use_sleep_only #include int test_value; void simple_thread() { test_value = 999; } void test_native_handle() { boost::thread_attributes attrs; boost::thread_attributes::native_handle_type h = attrs.native_handle(); #if defined(BOOST_THREAD_PLATFORM_WIN32) // ... window version #elif defined(BOOST_THREAD_PLATFORM_PTHREAD) BOOST_CHECK(!pthread_attr_setstacksize(&h, 1000000)); std::size_t res; BOOST_CHECK(!pthread_attr_getstacksize(&h, &res)); BOOST_CHECK(res==1000000); #else #error "Boost thread unavailable on this platform" #endif } void test_stack_size() { boost::thread_attributes attrs; attrs.set_stack_size(1000000u); BOOST_CHECK_EQUAL(attrs.get_stack_size(), 1000000u); } void do_test_creation_with_attrs() { test_value = 0; boost::thread_attributes attrs; attrs.set_stack_size(1000000); boost::thread thrd(attrs, &simple_thread); thrd.join(); BOOST_CHECK_EQUAL(test_value, 999); } void test_creation_with_attrs() { timed_test(&do_test_creation_with_attrs, 1); } boost::unit_test_framework::test_suite* init_unit_test_suite(int, char*[]) { boost::unit_test_framework::test_suite* test = BOOST_TEST_SUITE("Boost.Threads: thread attributes test suite"); test->add(BOOST_TEST_CASE(test_native_handle)); test->add(BOOST_TEST_CASE(test_stack_size)); test->add(BOOST_TEST_CASE(test_creation_with_attrs)); return test; }