1 // Copyright (C) 2008 Vicente J. Botet Escriba
2 // Distributed under the Boost Software License, Version 1.0. (See accompanying
3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 #define BOOST_THREAD_VERSION 2
6 #define BOOST_TEST_MODULE Boost.Threads: thread attributes test suite
7 #include <boost/thread/detail/config.hpp>
9 #include <boost/thread/thread_only.hpp>
10 #include <boost/thread/xtime.hpp>
11 #include <boost/bind/bind.hpp>
12 #include <boost/ref.hpp>
13 #include <boost/utility.hpp>
16 #include <boost/test/unit_test.hpp>
18 #define DEFAULT_EXECUTION_MONITOR_TYPE execution_monitor::use_sleep_only
22 #ifdef PTHREAD_STACK_MIN
23 #define MY_PTHREAD_STACK PTHREAD_STACK_MIN
25 #define MY_PTHREAD_STACK 4*0x4000
32 BOOST_AUTO_TEST_CASE(test_native_handle
)
35 boost::thread_attributes attrs
;
37 boost::thread_attributes::native_handle_type
* h
= attrs
.native_handle();
39 #if defined(BOOST_THREAD_PLATFORM_WIN32)
41 #elif defined(BOOST_THREAD_PLATFORM_PTHREAD)
43 int k
= pthread_attr_setstacksize(h
, MY_PTHREAD_STACK
);
44 std::cout
<< k
<< std::endl
;
45 BOOST_CHECK(!pthread_attr_setstacksize(h
, MY_PTHREAD_STACK
));
47 BOOST_CHECK(!pthread_attr_getstacksize(h
, &res
));
48 BOOST_CHECK(res
>= (MY_PTHREAD_STACK
));
50 #error "Boost thread unavailable on this platform"
55 BOOST_AUTO_TEST_CASE(test_stack_size
)
57 boost::thread_attributes attrs
;
59 attrs
.set_stack_size(0x4000);
60 BOOST_CHECK(attrs
.get_stack_size() >= 0x4000);
64 void do_test_creation_with_attrs()
67 boost::thread_attributes attrs
;
68 attrs
.set_stack_size(0x4000);
69 boost::thread
thrd(attrs
, &simple_thread
);
71 BOOST_CHECK_EQUAL(test_value
, 999);
74 BOOST_AUTO_TEST_CASE(test_creation_with_attrs
)
76 timed_test(&do_test_creation_with_attrs
, 1);