Subject: Re: [Boost-bugs] [Boost C++ Libraries] #10967: Timed wait points inconsistently convert relative to absolute waits
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-01-25 10:10:08
#10967: Timed wait points inconsistently convert relative to absolute waits
-------------------------------+----------------------
Reporter: ned14 | Owner: viboes
Type: Bugs | Status: assigned
Milestone: To Be Determined | Component: thread
Version: Boost 1.57.0 | Severity: Problem
Resolution: | Keywords:
-------------------------------+----------------------
Comment (by viboes):
E.g. it would be better to rename do_try_join_until to do_try_join_for.
This would not fix anything, but it will make things clearer.
{{{
diff --git a/include/boost/thread/detail/thread.hpp
b/include/boost/thread/detail/thread.hpp
index b80eacf..2774eb0 100644
--- a/include/boost/thread/detail/thread.hpp
+++ b/include/boost/thread/detail/thread.hpp
@@ -472,7 +472,7 @@ namespace boost
bool try_join_for(const chrono::duration<Rep, Period>& rel_time)
{
chrono::milliseconds rel_time2=
chrono::ceil<chrono::milliseconds>(rel_time);
- return do_try_join_until(rel_time2.count());
+ return do_try_join_for(rel_time2.count());
}
#else
template <class Rep, class Period>
@@ -504,19 +504,16 @@ namespace boost
#endif
#if defined(BOOST_THREAD_PLATFORM_WIN32)
private:
- bool do_try_join_until_noexcept(uintmax_t milli, bool& res);
- inline bool do_try_join_until(uintmax_t milli);
+ bool do_try_join_for_noexcept(uintmax_t milli, bool& res);
+ inline bool do_try_join_for(uintmax_t milli);
public:
bool timed_join(const system_time& abs_time);
- //{
- // return do_try_join_until(get_milliseconds_until(wait_until));
- //}
#ifdef BOOST_THREAD_USES_CHRONO
bool try_join_until(const
chrono::time_point<chrono::system_clock, chrono::nanoseconds>& tp)
{
chrono::milliseconds rel_time=
chrono::ceil<chrono::milliseconds>(tp-chrono::system_clock::now());
- return do_try_join_until(rel_time.count());
+ return do_try_join_for(rel_time.count());
}
#endif
@@ -769,9 +766,6 @@ namespace boost
#ifdef BOOST_THREAD_PLATFORM_PTHREAD
bool thread::do_try_join_until(struct timespec const &timeout)
-#else
- bool thread::do_try_join_until(uintmax_t timeout)
-#endif
{
if (this_thread::get_id() == get_id())
boost::throw_exception(thread_resource_error(static_cast<int>(system::errc::resource_deadlock_would_occur),
"boost thread: trying joining itself"));
@@ -788,6 +782,25 @@ namespace boost
);
}
}
+#else
+ bool thread::do_try_join_for(uintmax_t timeout)
+ {
+ if (this_thread::get_id() == get_id())
+
boost::throw_exception(thread_resource_error(static_cast<int>(system::errc::resource_deadlock_would_occur),
"boost thread: trying joining itself"));
+ bool res;
+ if (do_try_join_for_noexcept(timeout, res))
+ {
+ return res;
+ }
+ else
+ {
+ BOOST_THREAD_THROW_ELSE_RETURN(
+
(thread_resource_error(static_cast<int>(system::errc::invalid_argument),
"boost thread: thread not joinable")),
+ false
+ );
+ }
+ }
+#endif
#if !defined(BOOST_NO_IOSTREAM) &&
defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
template<class charT, class traits>
diff --git a/src/win32/thread.cpp b/src/win32/thread.cpp
index e02124f..2d9af0e 100644
--- a/src/win32/thread.cpp
+++ b/src/win32/thread.cpp
@@ -44,7 +44,7 @@
#include <wrl\ftm.h>
#include <windows.system.threading.h>
#pragma comment(lib, "runtimeobject.lib")
-#endif
+#endif
namespace boost
{
@@ -198,7 +198,7 @@ namespace boost
namespace detail
{
std::atomic_uint threadCount;
-
+
bool win32::scoped_winrt_thread::start(thread_func address, void
*parameter, unsigned int *thrdId)
{
Microsoft::WRL::ComPtr<ABI::Windows::System::Threading::IThreadPoolStatics>
threadPoolFactory;
@@ -220,7 +220,7 @@ namespace boost
m_completionHandle = completionHandle;
// Create new work item.
-
Microsoft::WRL::ComPtr<ABI::Windows::System::Threading::IWorkItemHandler>
workItem =
+
Microsoft::WRL::ComPtr<ABI::Windows::System::Threading::IWorkItemHandler>
workItem =
Microsoft::WRL::Callback<Microsoft::WRL::Implements<Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>,
ABI::Windows::System::Threading::IWorkItemHandler,
Microsoft::WRL::FtmBase>>
([address, parameter,
completionHandle](ABI::Windows::Foundation::IAsyncAction *)
{
@@ -346,7 +346,7 @@ namespace boost
return true;
#endif
}
-
+
bool thread::start_thread_noexcept(const attributes& attr)
{
#if BOOST_PLAT_WINDOWS_RUNTIME
@@ -367,7 +367,7 @@ namespace boost
return true;
#endif
}
-
+
thread::thread(detail::thread_data_ptr data):
thread_info(data)
{}
@@ -469,10 +469,10 @@ namespace boost
#if defined BOOST_THREAD_USES_DATETIME
bool thread::timed_join(boost::system_time const& wait_until)
{
- return do_try_join_until(get_milliseconds_until(wait_until));
+ return do_try_join_for(get_milliseconds_until(wait_until));
}
#endif
- bool thread::do_try_join_until_noexcept(uintmax_t milli, bool& res)
+ bool thread::do_try_join_for_noexcept(uintmax_t milli, bool& res)
{
detail::thread_data_ptr local_thread_info=(get_thread_info)();
if(local_thread_info)
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/10967#comment:3> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:17 UTC