2
0
mirror of https://github.com/boostorg/thread.git synced 2026-02-03 09:42:16 +00:00

Compare commits

...

17 Commits

Author SHA1 Message Date
Peter Dimov
7f7faf234d Merge branch 'develop' of https://github.com/mbs-c/thread into feature/pr-324 2022-07-05 20:50:14 +03:00
Peter Dimov
1de55fceda Fix test_366_4.cpp 2022-05-14 17:26:50 +03:00
Peter Dimov
8db325363b Disable interruptions in ~thread_guard, ~scoped_thread, ~strict_scoped_thread (refs #366, #367, #369) 2022-05-13 21:49:14 +03:00
Peter Dimov
f71e0f1645 Add test cases for issue #366 (also see comments in #367 and #369) 2022-05-13 21:41:54 +03:00
Peter Dimov
7f36ea346f Merge pull request #336 from eldiener/develop
[skip ci] Add "cxxstd" json field
2021-10-26 16:59:32 +03:00
Peter Dimov
660f293809 Remove all Windows jobs from ci.yml; the timeouts aren't sufficient and adjusting them all is too much work 2021-10-26 07:18:50 +03:00
Peter Dimov
d4b81d83f7 Remove mingw job; it's hopeless 2021-10-26 05:48:12 +03:00
Peter Dimov
e4d16eb4d9 Trim Windows jobs as they take too long 2021-10-26 05:47:43 +03:00
Peter Dimov
28a0a19cf0 Switch g++-5 to C++11 2021-10-26 05:07:37 +03:00
Peter Dimov
fca97a8826 Adjust warning suppression 2021-10-26 05:06:05 +03:00
Peter Dimov
48e639b124 Add .github/workflows 2021-10-26 03:53:10 +03:00
Peter Dimov
51f3e163b3 Merge branch 'develop' of https://github.com/Romain-Geissler-1A/thread into feature/pr-354 2021-10-26 02:00:43 +03:00
Peter Dimov
6fca28bfed Merge pull request #356 from Dani-Hub/Tolerable-delay-in-interruptible_wait-on-Win32-is-too-long-2
#348 Tolerable delay in interruptible_wait on Win32 is too long
2021-08-27 20:16:59 +03:00
Daniel Krügler
636e4a869c #348 Tolerable delay in interruptible_wait on Win32 is too long
Ensure that SetWaitableTimerEx's TolerableDelay parameter is clamped between 32 and 1000 ms when computing the 5% deviation.
2021-08-17 18:50:24 +02:00
Romain Geissler
f9d0e594d4 Fix -Wsign-compare warning with glibc 2.34 on Linux platforms.
In file included from /data/mwrep/res/osp/Boost/21-0-0-0/include/boost/thread/thread_only.hpp:17,
                 from /data/mwrep/res/osp/Boost/21-0-0-0/include/boost/thread/thread.hpp:12,
                 from src/GetTest.cpp:12:
/data/mwrep/res/osp/Boost/21-0-0-0/include/boost/thread/pthread/thread_data.hpp: In member function 'void boost::thread_attributes::set_stack_size(std::size_t)':
/data/mwrep/res/osp/Boost/21-0-0-0/include/boost/thread/pthread/thread_data.hpp:61:19: error: comparison of integer expressions of different signedness: 'std::size_t' {aka 'long unsigned int'} and 'long int' [-Werror=sign-compare]
   61 |           if (size<PTHREAD_STACK_MIN) size=PTHREAD_STACK_MIN;
      |                   ^
2021-08-10 14:22:28 +00:00
Edward Diener
c55e0952ee [skip ci] Add "cxxstd" json field. The "cxxstd" json field is being added to each Boost library's meta json information for libraries in order to specify the minumum C++ standard compilation level. The value of this field matches one of the values for 'cxxstd' in Boost.Build. The purpose of doing this is to provide information for the Boost website documentation for each library which will specify the minimum C++ standard compilation that an end-user must employ in order to use the particular library. This will aid end-users who want to know if they can successfully use a Boost library based on their C++ compiler's compilation level, without having to search the library's documentation to find this out. 2021-01-21 16:22:48 -05:00
Moritz Baumann
4bc126fc37 Update calling convention macros in thread_primitives.cpp 2020-08-11 10:07:39 +02:00
12 changed files with 288 additions and 9 deletions

82
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,82 @@
name: CI
on:
pull_request:
push:
branches:
- master
- develop
- feature/**
env:
UBSAN_OPTIONS: print_stacktrace=1
jobs:
posix:
strategy:
fail-fast: false
matrix:
include:
- toolset: gcc-4.8
os: ubuntu-18.04
install: g++-4.8
- toolset: gcc-5
cxxstd: 11
os: ubuntu-18.04
install: g++-5
- toolset: gcc-7
os: ubuntu-18.04
- toolset: gcc-9
os: ubuntu-20.04
- toolset: gcc-11
os: ubuntu-20.04
install: g++-11
- toolset: clang
compiler: clang++-12
cxxstd: 20
os: ubuntu-20.04
install: clang-12
- toolset: clang
os: macos-10.15
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- name: Install packages
if: matrix.install
run: sudo apt install ${{matrix.install}}
- name: Setup Boost
run: |
echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY
LIBRARY=${GITHUB_REPOSITORY#*/}
echo LIBRARY: $LIBRARY
echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV
echo GITHUB_BASE_REF: $GITHUB_BASE_REF
echo GITHUB_REF: $GITHUB_REF
REF=${GITHUB_BASE_REF:-$GITHUB_REF}
REF=${REF#refs/heads/}
echo REF: $REF
BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true
echo BOOST_BRANCH: $BOOST_BRANCH
cd ..
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
./bootstrap.sh
./b2 -d0 headers
- name: Create user-config.jam
if: matrix.compiler
run: |
echo "using ${{matrix.toolset}} : : ${{matrix.compiler}} ;" > ~/user-config.jam
- name: Run tests
run: |
cd ../boost-root
export CXXSTD=${{matrix.cxxstd}}
./b2 -j3 libs/$LIBRARY/test toolset=${{matrix.toolset}} ${CXXSTD:+cxxstd=$CXXSTD} variant=debug,release

View File

@@ -58,7 +58,7 @@ namespace boost
std::size_t page_size = ::sysconf( _SC_PAGESIZE);
#endif
#ifdef PTHREAD_STACK_MIN
if (size<PTHREAD_STACK_MIN) size=PTHREAD_STACK_MIN;
if (size<static_cast<std::size_t>(PTHREAD_STACK_MIN)) size=PTHREAD_STACK_MIN;
#endif
size = ((size+page_size-1)/page_size)*page_size;
int res = pthread_attr_setstacksize(&val_, size);

View File

@@ -14,6 +14,7 @@
#include <boost/thread/detail/move.hpp>
#include <boost/thread/thread_functors.hpp>
#include <boost/thread/thread_only.hpp>
#include <boost/thread/detail/thread_interruption.hpp>
#include <boost/config/abi_prefix.hpp>
@@ -85,6 +86,10 @@ namespace boost
*/
~strict_scoped_thread()
{
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
// exceptions from a destructor call std::terminate
boost::this_thread::disable_interruption do_not_disturb;
#endif
CallableThread on_destructor;
on_destructor(t_);
@@ -188,6 +193,10 @@ namespace boost
*/
~scoped_thread()
{
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
// exceptions from a destructor call std::terminate
boost::this_thread::disable_interruption do_not_disturb;
#endif
CallableThread on_destructor;
on_destructor(t_);

View File

@@ -12,6 +12,7 @@
#include <boost/thread/detail/delete.hpp>
#include <boost/thread/detail/move.hpp>
#include <boost/thread/thread_functors.hpp>
#include <boost/thread/detail/thread_interruption.hpp>
#include <boost/config/abi_prefix.hpp>
@@ -34,6 +35,10 @@ namespace boost
}
~thread_guard()
{
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
// exceptions from a destructor call std::terminate
boost::this_thread::disable_interruption do_not_disturb;
#endif
CallableThread on_destructor;
on_destructor(t_);

View File

@@ -14,6 +14,7 @@
"std": [ "proposal" ],
"category": [
"Concurrent", "System"
]
],
"cxxstd": "03"
}
]

View File

@@ -641,9 +641,15 @@ namespace boost
timer_handle=CreateWaitableTimer(NULL,false,NULL);
if(timer_handle!=0)
{
ULONG tolerable=32; // Empirical testing shows Windows ignores this when <= 26
ULONG const min_tolerable=32; // Empirical testing shows Windows ignores this when <= 26
ULONG const max_tolerable=1000;
ULONG tolerable=min_tolerable;
if(time_left_msec/20>tolerable) // 5%
{
tolerable=static_cast<ULONG>(time_left_msec/20);
if(tolerable>max_tolerable)
tolerable=max_tolerable;
}
LARGE_INTEGER due_time={{0,0}};
if(time_left_msec>0)
{
@@ -733,9 +739,15 @@ namespace boost
timer_handle=CreateWaitableTimer(NULL,false,NULL);
if(timer_handle!=0)
{
ULONG tolerable=32; // Empirical testing shows Windows ignores this when <= 26
ULONG const min_tolerable=32; // Empirical testing shows Windows ignores this when <= 26
ULONG const max_tolerable=1000;
ULONG tolerable=min_tolerable;
if(time_left_msec/20>tolerable) // 5%
{
tolerable=static_cast<ULONG>(time_left_msec/20);
if(tolerable>max_tolerable)
tolerable=max_tolerable;
}
LARGE_INTEGER due_time={{0,0}};
if(time_left_msec>0)
{

View File

@@ -52,7 +52,7 @@ struct get_tick_count64_state
BOOST_ALIGNMENT(64) static get_tick_count64_state g_state;
//! Artifical implementation of GetTickCount64
ticks_type WINAPI get_tick_count64()
ticks_type BOOST_WINAPI_WINAPI_CC get_tick_count64()
{
uint64_t old_state = g_state.ticks.load(boost::memory_order_acquire);
@@ -67,7 +67,7 @@ ticks_type WINAPI get_tick_count64()
}
//! The function is called periodically in the system thread pool to make sure g_state.ticks is timely updated
void NTAPI refresh_get_tick_count64(boost::winapi::PVOID_, boost::winapi::BOOLEAN_)
void BOOST_WINAPI_NTAPI_CC refresh_get_tick_count64(boost::winapi::PVOID_, boost::winapi::BOOLEAN_)
{
get_tick_count64();
}
@@ -88,7 +88,7 @@ void cleanup_get_tick_count64()
}
}
ticks_type WINAPI get_tick_count_init()
ticks_type BOOST_WINAPI_WINAPI_CC get_tick_count_init()
{
boost::winapi::HMODULE_ hKernel32 = boost::winapi::GetModuleHandleW(L"kernel32.dll");
if (hKernel32)

View File

@@ -34,8 +34,7 @@ project
<toolset>gcc:<cxxflags>-Wno-long-long
#<toolset>gcc:<cxxflags>-ansi
#<toolset>gcc:<cxxflags>-fpermissive
<toolset>gcc-4:<cxxflags>-Wno-variadic-macros
<toolset>gcc-5:<cxxflags>-Wno-variadic-macros
<toolset>gcc:<cxxflags>-Wno-variadic-macros
#<toolset>gcc:<cxxflags>-Wunused-local-typedefs
<toolset>gcc:<cxxflags>-Wunused-function
<toolset>gcc:<cxxflags>-Wno-unused-parameter
@@ -62,6 +61,7 @@ project
#<toolset>clang:<cxxflags>-fpermissive # doesn't work
<toolset>clang:<cxxflags>-Wunused-function
<toolset>clang:<cxxflags>-Wno-unused-parameter
<toolset>clang:<cxxflags>-Wno-c99-extensions
#<toolset>gcc-mingw-4.4.0:<cxxflags>-fdiagnostics-show-option
#<toolset>gcc-mingw-4.5.0:<cxxflags>-fdiagnostics-show-option
@@ -368,6 +368,10 @@ rule generate_self_contained_header_tests
[ thread-run test_10964.cpp ]
[ thread-test test_11053.cpp ]
[ thread-run test_11266.cpp ]
[ thread-run test_366_1.cpp ]
[ thread-run test_366_2.cpp ]
[ thread-run test_366_3.cpp ]
[ thread-run test_366_4.cpp ]
;

37
test/test_366_1.cpp Normal file
View File

@@ -0,0 +1,37 @@
// Copyright 2022 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include "boost/thread/thread_guard.hpp"
#include "boost/thread.hpp"
#include <boost/core/lightweight_test.hpp>
#include <iostream>
static void inner_thread_func()
{
boost::this_thread::sleep_for(
boost::chrono::hours(1) );
}
static void outer_thread_func()
{
boost::thread inner( inner_thread_func );
boost::thread_guard<boost::interrupt_and_join_if_joinable> guard( inner );
}
static void double_interrupt()
{
boost::thread outer( outer_thread_func );
boost::thread_guard<boost::interrupt_and_join_if_joinable> guard( outer );
}
int main()
{
BOOST_TEST( true ); // perform lwt initialization
std::cout << "Start" << std::endl;
double_interrupt();
std::cout << "End" << std::endl;
return boost::report_errors();
}

35
test/test_366_2.cpp Normal file
View File

@@ -0,0 +1,35 @@
// Copyright 2022 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include "boost/thread/scoped_thread.hpp"
#include "boost/thread.hpp"
#include <boost/core/lightweight_test.hpp>
#include <iostream>
static void inner_thread_func()
{
boost::this_thread::sleep_for(
boost::chrono::hours(1) );
}
static void outer_thread_func()
{
boost::scoped_thread<boost::interrupt_and_join_if_joinable> inner( inner_thread_func );
}
static void double_interrupt()
{
boost::scoped_thread<boost::interrupt_and_join_if_joinable> outer( outer_thread_func );
}
int main()
{
BOOST_TEST( true ); // perform lwt initialization
std::cout << "Start" << std::endl;
double_interrupt();
std::cout << "End" << std::endl;
return boost::report_errors();
}

35
test/test_366_3.cpp Normal file
View File

@@ -0,0 +1,35 @@
// Copyright 2022 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include "boost/thread/scoped_thread.hpp"
#include "boost/thread.hpp"
#include <boost/core/lightweight_test.hpp>
#include <iostream>
static void inner_thread_func()
{
boost::this_thread::sleep_for(
boost::chrono::hours(1) );
}
static void outer_thread_func()
{
boost::strict_scoped_thread<boost::interrupt_and_join_if_joinable> inner( inner_thread_func );
}
static void double_interrupt()
{
boost::strict_scoped_thread<boost::interrupt_and_join_if_joinable> outer( outer_thread_func );
}
int main()
{
BOOST_TEST( true ); // perform lwt initialization
std::cout << "Start" << std::endl;
double_interrupt();
std::cout << "End" << std::endl;
return boost::report_errors();
}

59
test/test_366_4.cpp Normal file
View File

@@ -0,0 +1,59 @@
// Copyright 2022 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include "boost/thread/scoped_thread.hpp"
#include "boost/thread.hpp"
#include <boost/core/lightweight_test.hpp>
#include <iostream>
static void do_first_half()
{
std::cout << "Doing first half of the work\n";
boost::this_thread::sleep_for(
boost::chrono::hours( 1 ) );
std::cout << "First half of the work complete\n";
}
static void do_second_half()
{
std::cout << "Doing second half of the work\n";
boost::this_thread::sleep_for(
boost::chrono::hours( 1 ) );
std::cout << "Second half of the work complete\n";
}
static void outer_thread_func()
{
boost::scoped_thread<boost::interrupt_and_join_if_joinable> worker1( do_first_half );
boost::scoped_thread<boost::interrupt_and_join_if_joinable> worker2( do_second_half );
worker1.join();
worker2.join();
}
int main()
{
BOOST_TEST( true ); // perform lwt initialization
std::cout << "Start" << std::endl;
{
boost::thread outer( outer_thread_func );
boost::this_thread::sleep_for( boost::chrono::seconds( 1 ) );
std::cout << "Interrupting work\n";
outer.interrupt();
outer.join();
}
std::cout << "End" << std::endl;
return boost::report_errors();
}