2
0
mirror of https://github.com/boostorg/thread.git synced 2026-02-09 23:42:18 +00:00
Files
thread/test/test_2741.cpp
Andrey Semashev ee609e8806 Cleanup header includes.
1. Make inclusion of boost/bind/bind.hpp conditional in some cases, when the
   code actually conditionally uses boost::bind. Reduces compile-time overhead
   and fixes https://github.com/boostorg/thread/issues/307.

2. Remove some unnecessary uses of boost::ref. This allows to avoid including
   boost/core/ref.hpp in a few places, and avoids the associated template
   instantiation overhead in others.

3. Replace deprecated header includes with the more recent alternatives. For
   example: boost/detail/lightweight_test.hpp -> boost/core/lightweight_test.hpp,
   boost/ref.hpp -> boost/core/ref.hpp.

4. Replace some blanket includes with the more fine-grained ones. For example,
   boost/utility.hpp, boost/atomic.hpp. This reduces compile time overhead.

5. Add some missing includes, for example, boost/core/ref.hpp and
   boost/type_traits/is_same.hpp.

6. Replace uses of std::is_same with boost::is_same (with the corresponding
   included header) since the standard type_traits header presence and validity
   is not tested by the code. Using boost::is_same makes the code more portable.
2020-04-05 01:51:58 +03:00

75 lines
1.8 KiB
C++

// 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)
#define BOOST_THREAD_VERSION 2
#define BOOST_TEST_MODULE Boost.Threads: thread attributes test suite
#include <boost/thread/detail/config.hpp>
#include <boost/thread/thread_only.hpp>
#include <boost/thread/xtime.hpp>
#include <iostream>
#include <boost/test/unit_test.hpp>
#define DEFAULT_EXECUTION_MONITOR_TYPE execution_monitor::use_sleep_only
#include "./util.inl"
int test_value;
#ifdef PTHREAD_STACK_MIN
#define MY_PTHREAD_STACK PTHREAD_STACK_MIN
#else
#define MY_PTHREAD_STACK 4*0x4000
#endif
void simple_thread()
{
test_value = 999;
}
BOOST_AUTO_TEST_CASE(test_native_handle)
{
boost::thread_attributes attrs;
boost::thread_attributes::native_handle_type* h = attrs.native_handle();
(void)(h); // unused
#if defined(BOOST_THREAD_PLATFORM_WIN32)
// ... window version
#elif defined(BOOST_THREAD_PLATFORM_PTHREAD)
int k = pthread_attr_setstacksize(h, MY_PTHREAD_STACK);
std::cout << k << std::endl;
BOOST_CHECK(!pthread_attr_setstacksize(h, MY_PTHREAD_STACK));
std::size_t res;
BOOST_CHECK(!pthread_attr_getstacksize(h, &res));
BOOST_CHECK(res >= (MY_PTHREAD_STACK));
#else
#error "Boost thread unavailable on this platform"
#endif
}
BOOST_AUTO_TEST_CASE(test_stack_size)
{
boost::thread_attributes attrs;
attrs.set_stack_size(0x4000);
BOOST_CHECK(attrs.get_stack_size() >= 0x4000);
}
void do_test_creation_with_attrs()
{
test_value = 0;
boost::thread_attributes attrs;
attrs.set_stack_size(0x4000);
boost::thread thrd(attrs, &simple_thread);
thrd.join();
BOOST_CHECK_EQUAL(test_value, 999);
}
BOOST_AUTO_TEST_CASE(test_creation_with_attrs)
{
timed_test(&do_test_creation_with_attrs, 1);
}