2
0
mirror of https://github.com/boostorg/thread.git synced 2026-02-04 22:02:10 +00:00

Compare commits

..

4 Commits

Author SHA1 Message Date
Vicente J. Botet Escriba
377bb87ad5 Merge branch 'develop' 2018-04-18 17:51:46 +02:00
Vicente J. Botet Escriba
180ca01c97 Merge pull request #217 from jschueller/patch-1
Windows.h > windows.h
2018-04-15 10:37:11 +02:00
Julien Schueller
a6dede8199 Windows.h > windows.h
Fixes build on case-sensitive fs
2018-04-15 08:33:56 +02:00
Vicente J. Botet Escriba
d268106bf8 Merge branch 'develop' 2018-03-04 23:12:43 +01:00
86 changed files with 382 additions and 1264 deletions

View File

@@ -38,8 +38,6 @@ import path ;
import configure ;
import threadapi-feature ;
exe has_atomic_flag_lockfree : ../build/has_atomic_flag_lockfree_test.cpp ;
project boost/thread
: source-location ../src
: requirements <threading>multi
@@ -143,6 +141,8 @@ project boost/thread
<library>/boost/system//boost_system
;
exe has_atomic_flag_lockfree : ../build/has_atomic_flag_lockfree_test.cpp ;
rule tag ( name : type ? : property-set )
{
local result = $(name) ;

View File

@@ -45,7 +45,7 @@ build_steps: &build_steps
command: |
echo "using $TOOLSET : : $COMPILER : <cxxflags>-std=$CXXSTD <cxxflags>$DEFINES ;" > ~/user-config.jam
cd ../boost-root
./b2 -j8 libs/thread/test toolset=$TOOLSET
./b2 -j10 libs/thread/test toolset=$TOOLSET
mac_build: &mac_build
macos:
@@ -66,6 +66,7 @@ jobs:
- TOOLSET: "gcc"
- COMPILER: "g++"
- CXXSTD: "c++11"
- DEFINES: "-DBOOST_THREAD_TEST_TIME_MS=100"
linux-g++-7-c++98:
<<: *linux_build
@@ -73,6 +74,7 @@ jobs:
- TOOLSET: "gcc"
- COMPILER: "g++-7"
- CXXSTD: "c++98"
- DEFINES: "-DBOOST_THREAD_TEST_TIME_MS=100"
linux-g++-7-c++11:
<<: *linux_build
@@ -80,6 +82,7 @@ jobs:
- TOOLSET: "gcc"
- COMPILER: "g++-7"
- CXXSTD: "c++11"
- DEFINES: "-DBOOST_THREAD_TEST_TIME_MS=100"
linux-g++-7-c++14:
<<: *linux_build
@@ -87,6 +90,7 @@ jobs:
- TOOLSET: "gcc"
- COMPILER: "g++-7"
- CXXSTD: "c++14"
- DEFINES: "-DBOOST_THREAD_TEST_TIME_MS=100"
linux-g++-7-c++1z:
<<: *linux_build
@@ -94,6 +98,7 @@ jobs:
- TOOLSET: "gcc"
- COMPILER: "g++-7"
- CXXSTD: "c++1z"
- DEFINES: "-DBOOST_THREAD_TEST_TIME_MS=100"
linux-clang++-4.0-c++98:
<<: *linux_build
@@ -101,6 +106,7 @@ jobs:
- TOOLSET: "clang"
- COMPILER: "clang++-4.0"
- CXXSTD: "c++98"
- DEFINES: "-DBOOST_THREAD_TEST_TIME_MS=100"
linux-clang++-4.0-c++11:
<<: *linux_build
@@ -108,6 +114,7 @@ jobs:
- TOOLSET: "clang"
- COMPILER: "clang++-4.0"
- CXXSTD: "c++11"
- DEFINES: "-DBOOST_THREAD_TEST_TIME_MS=100"
linux-clang++-4.0-c++14:
<<: *linux_build
@@ -115,6 +122,7 @@ jobs:
- TOOLSET: "clang"
- COMPILER: "clang++-4.0"
- CXXSTD: "c++14"
- DEFINES: "-DBOOST_THREAD_TEST_TIME_MS=100"
linux-clang++-4.0-c++1z:
<<: *linux_build
@@ -122,6 +130,7 @@ jobs:
- TOOLSET: "clang"
- COMPILER: "clang++-4.0"
- CXXSTD: "c++1z"
- DEFINES: "-DBOOST_THREAD_TEST_TIME_MS=100"
mac-clang++-c++98:
<<: *mac_build
@@ -129,7 +138,7 @@ jobs:
- TOOLSET: "clang"
- COMPILER: "clang++"
- CXXSTD: "c++98"
- DEFINES: "-DBOOST_THREAD_TEST_TIME_MS=100"
- DEFINES: "-DBOOST_THREAD_TEST_TIME_MS=170"
mac-clang++-c++11:
<<: *mac_build
@@ -137,7 +146,7 @@ jobs:
- TOOLSET: "clang"
- COMPILER: "clang++"
- CXXSTD: "c++11"
- DEFINES: "-DBOOST_THREAD_TEST_TIME_MS=100"
- DEFINES: "-DBOOST_THREAD_TEST_TIME_MS=170"
mac-clang++-c++14:
<<: *mac_build
@@ -145,7 +154,7 @@ jobs:
- TOOLSET: "clang"
- COMPILER: "clang++"
- CXXSTD: "c++14"
- DEFINES: "-DBOOST_THREAD_TEST_TIME_MS=100"
- DEFINES: "-DBOOST_THREAD_TEST_TIME_MS=170"
mac-clang++-c++1z:
<<: *mac_build
@@ -153,7 +162,7 @@ jobs:
- TOOLSET: "clang"
- COMPILER: "clang++"
- CXXSTD: "c++1z"
- DEFINES: "-DBOOST_THREAD_TEST_TIME_MS=100"
- DEFINES: "-DBOOST_THREAD_TEST_TIME_MS=170"
workflows:
version: 2

View File

@@ -1526,7 +1526,7 @@ A thread pool with up to a fixed number of threads.
[variablelist
[[Effects:] [Interrupts and joins all the threads and then destroys the threads.]]
[[Effects:] [Destroys the thread pool.]]
[[Synchronization:] [The completion of all the closures happen before the completion of the executor destructor.]]

View File

@@ -11,7 +11,6 @@
#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/thread/detail/platform.hpp>
#include <boost/thread/detail/thread_safety.hpp>
//#define BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS
// ATTRIBUTE_MAY_ALIAS

View File

@@ -3,7 +3,7 @@
// 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)
//
// 2013,2018 Vicente J. Botet Escriba
// 2013/09 Vicente J. Botet Escriba
// Adapt to boost from CCIA C++11 implementation
// Make use of Boost.Move
@@ -15,7 +15,6 @@
#include <boost/thread/detail/move.hpp>
#include <boost/thread/csbl/memory/shared_ptr.hpp>
#include <boost/type_traits/decay.hpp>
#include <boost/type_traits/is_same.hpp>
namespace boost
{
@@ -73,16 +72,12 @@ namespace boost
#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
template<typename F>
explicit nullary_function(F& f
, typename disable_if<is_same<typename decay<F>::type, nullary_function>, int* >::type=0
):
explicit nullary_function(F& f):
impl(new impl_type<F>(f))
{}
#endif
template<typename F>
nullary_function(BOOST_THREAD_RV_REF(F) f
, typename disable_if<is_same<typename decay<F>::type, nullary_function>, int* >::type=0
):
nullary_function(BOOST_THREAD_RV_REF(F) f):
impl(new impl_type<typename decay<F>::type>(thread_detail::decay_copy(boost::forward<F>(f))))
{}

View File

@@ -594,7 +594,7 @@ namespace boost
#endif
#if defined BOOST_THREAD_USES_DATETIME
inline BOOST_SYMBOL_VISIBLE void sleep(::boost::xtime const& abs_time)
inline BOOST_SYMBOL_VISIBLE void sleep(xtime const& abs_time)
{
sleep(system_time(abs_time));
}

View File

@@ -1,151 +0,0 @@
#ifndef BOOST_THREAD_DETAIL_THREAD_SAFETY_HPP
#define BOOST_THREAD_DETAIL_THREAD_SAFETY_HPP
// See https://clang.llvm.org/docs/ThreadSafetyAnalysis.html
// Un-comment to enable Thread Safety Analysis
//#define BOOST_THREAD_ENABLE_THREAD_SAFETY_ANALYSIS
// Enable thread safety attributes only with clang.
// The attributes can be safely erased when compiling with other compilers.
#if defined (BOOST_THREAD_ENABLE_THREAD_SAFETY_ANALYSIS) && defined(__clang__) && (!defined(SWIG))
#define BOOST_THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x))
#else
#define BOOST_THREAD_ANNOTATION_ATTRIBUTE__(x) // no-op
#endif
#define BOOST_THREAD_CAPABILITY(x) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(capability(x))
#define BOOST_THREAD_SCOPED_CAPABILITY \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable)
#define BOOST_THREAD_GUARDED_BY(x) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x))
#define BOOST_THREAD_PT_GUARDED_BY(x) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_by(x))
#define BOOST_THREAD_ACQUIRED_BEFORE(...) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(__VA_ARGS__))
#define BOOST_THREAD_ACQUIRED_AFTER(...) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(acquired_after(__VA_ARGS__))
#define BOOST_THREAD_REQUIRES(...) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(requires_capability(__VA_ARGS__))
#define BOOST_THREAD_REQUIRES_SHARED(...) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(requires_shared_capability(__VA_ARGS__))
#define BOOST_THREAD_ACQUIRE(...) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(acquire_capability(__VA_ARGS__))
#define BOOST_THREAD_ACQUIRE_SHARED(...) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(acquire_shared_capability(__VA_ARGS__))
#define BOOST_THREAD_RELEASE(...) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(release_capability(__VA_ARGS__))
#define BOOST_THREAD_RELEASE_SHARED(...) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(release_shared_capability(__VA_ARGS__))
#define BOOST_THREAD_TRY_ACQUIRE(...) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_capability(__VA_ARGS__))
#define BOOST_THREAD_TRY_ACQUIRE_SHARED(...) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_shared_capability(__VA_ARGS__))
#define BOOST_THREAD_EXCLUDES(...) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(__VA_ARGS__))
#define BOOST_THREAD_ASSERT_CAPABILITY(x) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(assert_capability(x))
#define BOOST_THREAD_ASSERT_SHARED_CAPABILITY(x) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(assert_shared_capability(x))
#define BOOST_THREAD_RETURN_CAPABILITY(x) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x))
#define BOOST_THREAD_NO_THREAD_SAFETY_ANALYSIS \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis)
#if defined(__clang__) && (!defined(SWIG)) && defined(__FreeBSD__)
#if __has_attribute(no_thread_safety_analysis)
#define BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS __attribute__((no_thread_safety_analysis))
#else
#define BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
#endif
#else
#define BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
#endif
#ifdef USE_LOCK_STYLE_THREAD_SAFETY_ATTRIBUTES
// The original version of thread safety analysis the following attribute
// definitions. These use a lock-based terminology. They are still in use
// by existing thread safety code, and will continue to be supported.
// Deprecated.
#define BOOST_THREAD_PT_GUARDED_VAR \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_var)
// Deprecated.
#define BOOST_THREAD_GUARDED_VAR \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(guarded_var)
// Replaced by REQUIRES
#define BOOST_THREAD_EXCLUSIVE_LOCKS_REQUIRED(...) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(exclusive_locks_required(__VA_ARGS__))
// Replaced by REQUIRES_SHARED
#define BOOST_THREAD_SHARED_LOCKS_REQUIRED(...) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(shared_locks_required(__VA_ARGS__))
// Replaced by CAPABILITY
#define BOOST_THREAD_LOCKABLE \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(lockable)
// Replaced by SCOPED_CAPABILITY
#define BOOST_THREAD_SCOPED_LOCKABLE \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable)
// Replaced by ACQUIRE
#define BOOST_THREAD_EXCLUSIVE_LOCK_FUNCTION(...) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(exclusive_lock_function(__VA_ARGS__))
// Replaced by ACQUIRE_SHARED
#define BOOST_THREAD_SHARED_LOCK_FUNCTION(...) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(shared_lock_function(__VA_ARGS__))
// Replaced by RELEASE and RELEASE_SHARED
#define BOOST_THREAD_UNLOCK_FUNCTION(...) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(unlock_function(__VA_ARGS__))
// Replaced by TRY_ACQUIRE
#define BOOST_THREAD_EXCLUSIVE_TRYLOCK_FUNCTION(...) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(exclusive_trylock_function(__VA_ARGS__))
// Replaced by TRY_ACQUIRE_SHARED
#define BOOST_THREAD_SHARED_TRYLOCK_FUNCTION(...) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(shared_trylock_function(__VA_ARGS__))
// Replaced by ASSERT_CAPABILITY
#define BOOST_THREAD_ASSERT_EXCLUSIVE_LOCK(...) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(assert_exclusive_lock(__VA_ARGS__))
// Replaced by ASSERT_SHARED_CAPABILITY
#define BOOST_THREAD_ASSERT_SHARED_LOCK(...) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(assert_shared_lock(__VA_ARGS__))
// Replaced by EXCLUDE_CAPABILITY.
#define BOOST_THREAD_LOCKS_EXCLUDED(...) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(__VA_ARGS__))
// Replaced by RETURN_CAPABILITY
#define BOOST_THREAD_LOCK_RETURNED(x) \
BOOST_THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x))
#endif // USE_LOCK_STYLE_THREAD_SAFETY_ATTRIBUTES
#endif // BOOST_THREAD_DETAIL_THREAD_SAFETY_HPP

View File

@@ -231,36 +231,13 @@ namespace executors
// signal to all the worker threads that there will be no more submissions.
close();
// joins all the threads before destroying the thread pool resources (e.g. the queue).
interrupt_and_join();
join();
}
/**
* \b Effects: join all the threads.
*/
void join()
{
for (unsigned i = 0; i < threads.size(); ++i)
{
//threads[i].interrupt();
threads[i].join();
}
}
/**
* \b Effects: interrupt all the threads.
*/
void interrupt()
{
for (unsigned i = 0; i < threads.size(); ++i)
{
threads[i].interrupt();
}
}
/**
* \b Effects: interrupt and join all the threads.
*/
void interrupt_and_join()
{
for (unsigned i = 0; i < threads.size(); ++i)
{

View File

@@ -18,11 +18,11 @@
#ifdef BOOST_NO_EXCEPTIONS
namespace boost
{
namespace detail {
struct shared_state_base {
void notify_deferred() {}
void notify_deferred();
};
}
}
#else

View File

@@ -23,7 +23,7 @@ namespace boost
{
template <typename Mutex>
class BOOST_THREAD_SCOPED_CAPABILITY lock_guard
class lock_guard
{
private:
Mutex& m;
@@ -32,13 +32,13 @@ namespace boost
typedef Mutex mutex_type;
BOOST_THREAD_NO_COPYABLE( lock_guard )
explicit lock_guard(Mutex& m_) BOOST_THREAD_ACQUIRE(m_) :
explicit lock_guard(Mutex& m_) :
m(m_)
{
m.lock();
}
lock_guard(Mutex& m_, adopt_lock_t) BOOST_THREAD_REQUIRES(m_) :
lock_guard(Mutex& m_, adopt_lock_t) :
m(m_)
{
#if ! defined BOOST_THREAD_PROVIDES_NESTED_LOCKS
@@ -62,7 +62,7 @@ namespace boost
}
#endif
~lock_guard() BOOST_THREAD_RELEASE()
~lock_guard()
{
m.unlock();
}

View File

@@ -249,7 +249,7 @@ namespace boost
#endif
}
template<typename lock_type>
bool timed_wait(lock_type& m,::boost::xtime const& abs_time)
bool timed_wait(lock_type& m,xtime const& abs_time)
{
return timed_wait(m,system_time(abs_time));
}
@@ -309,7 +309,7 @@ namespace boost
}
template<typename lock_type,typename predicate_type>
bool timed_wait(lock_type& m,::boost::xtime const& abs_time, predicate_type pred)
bool timed_wait(lock_type& m,xtime const& abs_time, predicate_type pred)
{
return timed_wait(m,system_time(abs_time),pred);
}

View File

@@ -128,7 +128,7 @@ namespace boost
}
bool timed_wait(
unique_lock<mutex>& m,
::boost::xtime const& abs_time)
xtime const& abs_time)
{
return timed_wait(m,system_time(abs_time));
}
@@ -194,7 +194,7 @@ namespace boost
template<typename predicate_type>
bool timed_wait(
unique_lock<mutex>& m,
::boost::xtime const& abs_time,predicate_type pred)
xtime const& abs_time,predicate_type pred)
{
return timed_wait(m,system_time(abs_time),pred);
}

View File

@@ -39,8 +39,53 @@
namespace boost
{
namespace posix {
#ifdef BOOST_THREAD_HAS_EINTR_BUG
BOOST_FORCEINLINE int pthread_mutex_destroy(pthread_mutex_t* m)
{
int ret;
do
{
ret = ::pthread_mutex_destroy(m);
} while (ret == EINTR);
return ret;
}
BOOST_FORCEINLINE int pthread_mutex_lock(pthread_mutex_t* m)
{
int ret;
do
{
ret = ::pthread_mutex_lock(m);
} while (ret == EINTR);
return ret;
}
BOOST_FORCEINLINE int pthread_mutex_unlock(pthread_mutex_t* m)
{
int ret;
do
{
ret = ::pthread_mutex_unlock(m);
} while (ret == EINTR);
return ret;
}
#else
BOOST_FORCEINLINE int pthread_mutex_destroy(pthread_mutex_t* m)
{
return ::pthread_mutex_destroy(m);
}
BOOST_FORCEINLINE int pthread_mutex_lock(pthread_mutex_t* m)
{
return ::pthread_mutex_lock(m);
}
BOOST_FORCEINLINE int pthread_mutex_unlock(pthread_mutex_t* m)
{
return ::pthread_mutex_unlock(m);
}
class BOOST_THREAD_CAPABILITY("mutex") mutex
#endif
}
class mutex
{
private:
pthread_mutex_t m;
@@ -62,7 +107,7 @@ namespace boost
BOOST_ASSERT(!res);
}
void lock() BOOST_THREAD_ACQUIRE()
void lock()
{
int res = posix::pthread_mutex_lock(&m);
if (res)
@@ -71,7 +116,7 @@ namespace boost
}
}
void unlock() BOOST_THREAD_RELEASE()
void unlock()
{
int res = posix::pthread_mutex_unlock(&m);
(void)res;
@@ -82,12 +127,12 @@ namespace boost
// }
}
bool try_lock() BOOST_THREAD_TRY_ACQUIRE(true)
bool try_lock()
{
int res;
do
{
res = posix::pthread_mutex_trylock(&m);
res = pthread_mutex_trylock(&m);
} while (res == EINTR);
if (res==EBUSY)
{
@@ -206,7 +251,7 @@ namespace boost
int res;
do
{
res = posix::pthread_mutex_trylock(&m);
res = pthread_mutex_trylock(&m);
} while (res == EINTR);
if (res==EBUSY)
{
@@ -232,7 +277,7 @@ namespace boost
boost::pthread::pthread_mutex_scoped_lock const local_lock(&m);
while(is_locked)
{
BOOST_VERIFY(!posix::pthread_cond_wait(&cond,&m));
BOOST_VERIFY(!pthread_cond_wait(&cond,&m));
}
is_locked=true;
}
@@ -241,7 +286,7 @@ namespace boost
{
boost::pthread::pthread_mutex_scoped_lock const local_lock(&m);
is_locked=false;
BOOST_VERIFY(!posix::pthread_cond_signal(&cond));
BOOST_VERIFY(!pthread_cond_signal(&cond));
}
bool try_lock()

View File

@@ -13,75 +13,6 @@
namespace boost
{
namespace posix {
#ifdef BOOST_THREAD_HAS_EINTR_BUG
BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
int pthread_mutex_destroy(pthread_mutex_t* m)
{
int ret;
do
{
ret = ::pthread_mutex_destroy(m);
} while (ret == EINTR);
return ret;
}
BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
int pthread_mutex_lock(pthread_mutex_t* m)
{
int ret;
do
{
ret = ::pthread_mutex_lock(m);
} while (ret == EINTR);
return ret;
}
BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
int pthread_mutex_unlock(pthread_mutex_t* m)
{
int ret;
do
{
ret = ::pthread_mutex_unlock(m);
} while (ret == EINTR);
return ret;
}
#else
BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
int pthread_mutex_destroy(pthread_mutex_t* m)
{
return ::pthread_mutex_destroy(m);
}
BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
int pthread_mutex_lock(pthread_mutex_t* m)
{
return ::pthread_mutex_lock(m);
}
BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
int pthread_mutex_unlock(pthread_mutex_t* m)
{
return ::pthread_mutex_unlock(m);
}
#endif
BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
int pthread_mutex_trylock(pthread_mutex_t* m)
{
return ::pthread_mutex_trylock(m);
}
BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
{
return ::pthread_cond_wait(cond, mutex);
}
BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
int pthread_cond_signal(pthread_cond_t *cond)
{
return ::pthread_cond_signal(cond);
}
}
namespace pthread
{
class pthread_mutex_scoped_lock
@@ -92,11 +23,11 @@ namespace posix {
explicit pthread_mutex_scoped_lock(pthread_mutex_t* m_) BOOST_NOEXCEPT:
m(m_),locked(true)
{
BOOST_VERIFY(!posix::pthread_mutex_lock(m));
BOOST_VERIFY(!pthread_mutex_lock(m));
}
void unlock() BOOST_NOEXCEPT
{
BOOST_VERIFY(!posix::pthread_mutex_unlock(m));
BOOST_VERIFY(!pthread_mutex_unlock(m));
locked=false;
}
void unlock_if_locked() BOOST_NOEXCEPT
@@ -123,11 +54,11 @@ namespace posix {
explicit pthread_mutex_scoped_unlock(pthread_mutex_t* m_) BOOST_NOEXCEPT:
m(m_)
{
BOOST_VERIFY(!posix::pthread_mutex_unlock(m));
BOOST_VERIFY(!pthread_mutex_unlock(m));
}
~pthread_mutex_scoped_unlock() BOOST_NOEXCEPT
{
BOOST_VERIFY(!posix::pthread_mutex_lock(m));
BOOST_VERIFY(!pthread_mutex_lock(m));
}
};

View File

@@ -105,17 +105,17 @@ namespace boost
#ifdef BOOST_THREAD_HAS_PTHREAD_MUTEXATTR_SETTYPE
void lock()
{
BOOST_VERIFY(!posix::pthread_mutex_lock(&m));
BOOST_VERIFY(!pthread_mutex_lock(&m));
}
void unlock()
{
BOOST_VERIFY(!posix::pthread_mutex_unlock(&m));
BOOST_VERIFY(!pthread_mutex_unlock(&m));
}
bool try_lock() BOOST_NOEXCEPT
{
int const res=posix::pthread_mutex_trylock(&m);
int const res=pthread_mutex_trylock(&m);
BOOST_ASSERT(!res || res==EBUSY);
return !res;
}
@@ -270,17 +270,17 @@ namespace boost
#ifdef BOOST_USE_PTHREAD_RECURSIVE_TIMEDLOCK
void lock()
{
BOOST_VERIFY(!posix::pthread_mutex_lock(&m));
BOOST_VERIFY(!pthread_mutex_lock(&m));
}
void unlock()
{
BOOST_VERIFY(!posix::pthread_mutex_unlock(&m));
BOOST_VERIFY(!pthread_mutex_unlock(&m));
}
bool try_lock()
{
int const res=posix::pthread_mutex_trylock(&m);
int const res=pthread_mutex_trylock(&m);
BOOST_ASSERT(!res || res==EBUSY);
return !res;
}

View File

@@ -12,7 +12,6 @@
#include <boost/thread/lock_types.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/pthread/condition_variable_fwd.hpp>
#include <boost/thread/pthread/pthread_mutex_scoped_lock.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
@@ -57,7 +56,7 @@ namespace boost
#else
std::size_t page_size = ::sysconf( _SC_PAGESIZE);
#endif
#if PTHREAD_STACK_MIN > 0
#ifdef PTHREAD_STACK_MIN
if (size<PTHREAD_STACK_MIN) size=PTHREAD_STACK_MIN;
#endif
size = ((size+page_size-1)/page_size)*page_size;
@@ -210,11 +209,11 @@ namespace boost
check_for_interruption();
thread_info->cond_mutex=cond_mutex;
thread_info->current_cond=cond;
BOOST_VERIFY(!posix::pthread_mutex_lock(m));
BOOST_VERIFY(!pthread_mutex_lock(m));
}
else
{
BOOST_VERIFY(!posix::pthread_mutex_lock(m));
BOOST_VERIFY(!pthread_mutex_lock(m));
}
}
void unlock_if_locked()
@@ -222,14 +221,14 @@ namespace boost
if ( ! done) {
if (set)
{
BOOST_VERIFY(!posix::pthread_mutex_unlock(m));
BOOST_VERIFY(!pthread_mutex_unlock(m));
lock_guard<mutex> guard(thread_info->data_mutex);
thread_info->cond_mutex=NULL;
thread_info->current_cond=NULL;
}
else
{
BOOST_VERIFY(!posix::pthread_mutex_unlock(m));
BOOST_VERIFY(!pthread_mutex_unlock(m));
}
done = true;
}

View File

@@ -67,7 +67,7 @@ namespace boost
template<typename Duration>
bool timed_lock(Duration const& target)
{
long const current_thread_id=boost::winapi::GetCurrentThreadId();
long const current_thread_id=boost::detail::winapi::GetCurrentThreadId();
return try_recursive_lock(current_thread_id) || try_timed_lock(current_thread_id,target);
}
#endif
@@ -76,13 +76,13 @@ namespace boost
template <class Rep, class Period>
bool try_lock_for(const chrono::duration<Rep, Period>& rel_time)
{
long const current_thread_id=boost::winapi::GetCurrentThreadId();
long const current_thread_id=boost::detail::winapi::GetCurrentThreadId();
return try_recursive_lock(current_thread_id) || try_timed_lock_for(current_thread_id,rel_time);
}
template <class Clock, class Duration>
bool try_lock_until(const chrono::time_point<Clock, Duration>& t)
{
long const current_thread_id=boost::winapi::GetCurrentThreadId();
long const current_thread_id=boost::detail::winapi::GetCurrentThreadId();
return try_recursive_lock(current_thread_id) || try_timed_lock_until(current_thread_id,t);
}
#endif

View File

@@ -57,17 +57,17 @@ struct xtime
};
inline ::boost::xtime get_xtime(boost::system_time const& abs_time)
inline xtime get_xtime(boost::system_time const& abs_time)
{
::boost::xtime res;
xtime res;
boost::posix_time::time_duration const time_since_epoch=abs_time-boost::posix_time::from_time_t(0);
res.sec=static_cast< ::boost::xtime::xtime_sec_t>(time_since_epoch.total_seconds());
res.nsec=static_cast< ::boost::xtime::xtime_nsec_t>(time_since_epoch.fractional_seconds()*(1000000000/time_since_epoch.ticks_per_second()));
res.sec=static_cast<xtime::xtime_sec_t>(time_since_epoch.total_seconds());
res.nsec=static_cast<xtime::xtime_nsec_t>(time_since_epoch.fractional_seconds()*(1000000000/time_since_epoch.ticks_per_second()));
return res;
}
inline int xtime_get(struct ::boost::xtime* xtp, int clock_type)
inline int xtime_get(struct xtime* xtp, int clock_type)
{
if (clock_type == TIME_UTC_)
{
@@ -78,7 +78,7 @@ inline int xtime_get(struct ::boost::xtime* xtp, int clock_type)
}
inline int xtime_cmp(const ::boost::xtime& xt1, const ::boost::xtime& xt2)
inline int xtime_cmp(const xtime& xt1, const xtime& xt2)
{
if (xt1.sec == xt2.sec)
return (int)(xt1.nsec - xt2.nsec);

View File

@@ -5,7 +5,14 @@
#include <boost/thread/detail/config.hpp>
#ifndef BOOST_NO_EXCEPTIONS
#ifdef BOOST_NO_EXCEPTIONS
namespace boost
{
void shared_state_base::notify_deferred() {}
}
#else
#include <boost/thread/futures/future_error_code.hpp>
#include <string>

View File

@@ -470,7 +470,7 @@ namespace boost
# elif defined(BOOST_HAS_PTHREAD_YIELD)
BOOST_VERIFY(!pthread_yield());
//# elif defined BOOST_THREAD_USES_DATETIME
// ::boost::xtime xt;
// xtime xt;
// xtime_get(&xt, TIME_UTC_);
// sleep(xt);
// sleep_for(chrono::milliseconds(0));
@@ -478,7 +478,7 @@ namespace boost
mutex mx;
unique_lock<mutex> lock(mx);
condition_variable cond;
cond.do_wait_until(lock, detail::internal_platform_clock::now());
cond.do_wait_until(lock, detail::internal_platform_clock::now())
# endif
}
}

View File

@@ -522,12 +522,12 @@ namespace boost
GetLogicalProcessorInformation(NULL, &size);
if (ERROR_INSUFFICIENT_BUFFER != GetLastError())
return 0;
const size_t Elements = size / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
std::vector<SYSTEM_LOGICAL_PROCESSOR_INFORMATION> buffer(Elements);
std::vector<SYSTEM_LOGICAL_PROCESSOR_INFORMATION> buffer(size);
if (GetLogicalProcessorInformation(&buffer.front(), &size) == FALSE)
return 0;
const size_t Elements = size / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
for (size_t i = 0; i < Elements; ++i) {
if (buffer[i].Relationship == RelationProcessorCore)

View File

@@ -93,24 +93,8 @@ ticks_type WINAPI get_tick_count_init()
boost::winapi::HMODULE_ hKernel32 = boost::winapi::GetModuleHandleW(L"kernel32.dll");
if (hKernel32)
{
// GetProcAddress returns a pointer to some function. It can return
// pointers to different functions, so it has to return something that is
// suitable to store any pointer to function. Microsoft chose FARPROC,
// which is int (WINAPI *)() on 32-bit Windows. The user is supposed to
// know the signature of the function he requests and perform a cast
// (which is a nop on this platform). The result is a pointer to function
// with the required signature, which is bitwise equal to what
// GetProcAddress returned.
// However, gcc >= 8 warns about that.
#if defined(BOOST_GCC) && BOOST_GCC >= 80000
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-function-type"
#endif
boost::detail::win32::detail::gettickcount64_t p =
(boost::detail::win32::detail::gettickcount64_t)boost::winapi::get_proc_address(hKernel32, "GetTickCount64");
#if defined(BOOST_GCC) && BOOST_GCC >= 80000
#pragma GCC diagnostic pop
#endif
if (p)
{
// Use native API

View File

@@ -208,36 +208,6 @@ rule thread-compile-fail ( sources : reqs * : name )
;
}
rule clang-thread-safety ( properties * )
{
if <toolset>clang in $(properties)
{
return <cxxflags>-Werror=thread-safety <define>BOOST_THREAD_ENABLE_THREAD_SAFETY_ANALYSIS ;
}
else
{
return <build>no ;
}
}
rule thread-safety-compile ( sources : reqs * : name )
{
return
[ compile $(sources)
: $(reqs) <conditional>@clang-thread-safety
: $(name) ]
;
}
rule thread-safety-compile-fail ( sources : reqs * : name )
{
return
[ compile-fail $(sources)
: $(reqs) <conditional>@clang-thread-safety
: $(name) ]
;
}
rule thread-compile ( sources : reqs * : name )
{
return
@@ -491,10 +461,6 @@ rule thread-compile ( sources : reqs * : name )
:
[ thread-compile-fail ./sync/mutual_exclusion/locks/lock_guard/copy_assign_fail.cpp : : lock_guard__cons__copy_assign_f ]
[ thread-compile-fail ./sync/mutual_exclusion/locks/lock_guard/copy_ctor_fail.cpp : : lock_guard__cons__copy_ctor_f ]
[ thread-safety-compile ./sync/mutual_exclusion/locks/lock_guard/lock_guard_compile_pass.cpp : : lock_guard__lock_compile_p ]
[ thread-safety-compile-fail ./sync/mutual_exclusion/locks/lock_guard/lock_guard_compile_fail.cpp : : lock_guard__lock_compile_f ]
[ thread-safety-compile ./sync/mutual_exclusion/locks/lock_guard/lock_guard_adopt_lock_compile_pass.cpp : : lock_guard__adopt_lock_compile_p ]
[ thread-safety-compile-fail ./sync/mutual_exclusion/locks/lock_guard/lock_guard_adopt_lock_compile_fail.cpp : : lock_guard__adopt_lock_compile_f ]
[ thread-run2-noit ./sync/mutual_exclusion/locks/lock_guard/adopt_lock_pass.cpp : lock_guard__cons__adopt_lock_p ]
[ thread-run2-noit ./sync/mutual_exclusion/locks/lock_guard/default_pass.cpp : lock_guard__cons__default_p ]
[ thread-run2-noit ./sync/mutual_exclusion/locks/lock_guard/types_pass.cpp : lock_guard__types_p ]
@@ -649,12 +615,6 @@ rule thread-compile ( sources : reqs * : name )
:
[ thread-compile-fail ./sync/mutual_exclusion/mutex/assign_fail.cpp : : mutex__assign_f ]
[ thread-compile-fail ./sync/mutual_exclusion/mutex/copy_fail.cpp : : mutex__copy_f ]
[ thread-safety-compile ./sync/mutual_exclusion/mutex/lock_compile_pass.cpp : : mutex__lock_compile_p ]
[ thread-safety-compile-fail ./sync/mutual_exclusion/mutex/lock_compile_fail.cpp : : mutex__lock_compile_f ]
# https://bugs.llvm.org/show_bug.cgi?id=32954
# http://clang-developers.42468.n3.nabble.com/thread-safety-warnings-specifically-try-acquire-capability-td4059337.html
#[ thread-safety-compile ./sync/mutual_exclusion/mutex/try_lock_compile_pass.cpp : : mutex__try_lock_compile_p ]
[ thread-safety-compile-fail ./sync/mutual_exclusion/mutex/try_lock_compile_fail.cpp : : mutex__try_lock_compile_f ]
[ thread-run2-noit ./sync/mutual_exclusion/mutex/default_pass.cpp : mutex__default_p ]
[ thread-run2-noit ./sync/mutual_exclusion/mutex/lock_pass.cpp : mutex__lock_p ]
[ thread-run2-noit-pthread ./sync/mutual_exclusion/mutex/native_handle_pass.cpp : mutex__native_handle_p ]
@@ -1011,8 +971,7 @@ rule thread-compile ( sources : reqs * : name )
#[ thread-run test_11796.cpp ]
#[ thread-run test_12293.cpp ]
#[ thread-run test_12949.cpp ]
#[ thread-run test_13480b.cpp ]
[ thread-run test_13561.cpp ]
[ thread-run test_13480b.cpp ]
;

View File

@@ -237,5 +237,5 @@ int main()
test_chrono_wait_function(wait_for_with_pred);
#endif
return boost::report_errors();
return 0;
}

View File

@@ -67,14 +67,12 @@ void f()
Clock::time_point t1 = Clock::now();
if (runs == 0)
{
ns d = t1 - t0;
BOOST_THREAD_TEST_IT(d, ns(max_diff));
assert(t1 - t0 < max_diff);
assert(test2 != 0);
}
else
{
ns d = t1 - t0 - Clock::duration(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
assert(t1 - t0 - Clock::duration(250) < max_diff);
assert(test2 == 0);
}
++runs;

View File

@@ -237,5 +237,5 @@ int main()
test_chrono_wait_function(wait_for_with_pred);
#endif
return boost::report_errors();
return 0;
}

View File

@@ -59,7 +59,6 @@ int main()
BOOST_TEST(!p0.valid());
BOOST_TEST(!p.valid());
}
return boost::report_errors();
}

View File

@@ -205,6 +205,7 @@ int main()
BOOST_TEST(all.valid());
BOOST_TEST(! all.is_ready());
pt1();
BOOST_TEST(! all.is_ready());
pt2();
boost::this_thread::sleep_for(boost::chrono::milliseconds(300));
BOOST_TEST(all.is_ready());

View File

@@ -169,6 +169,7 @@ int main()
BOOST_TEST(all.valid());
BOOST_TEST(! all.is_ready());
pt1();
BOOST_TEST(! all.is_ready());
pt2();
boost::this_thread::sleep_for(boost::chrono::milliseconds(300));
BOOST_TEST(all.is_ready());

View File

@@ -30,8 +30,6 @@ typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#endif
boost::mutex m;
@@ -40,12 +38,15 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
#ifdef BOOST_THREAD_USES_CHRONO
t0 = Clock::now();
time_point t0 = Clock::now();
time_point t1;
{
m.lock();
boost::lock_guard<boost::mutex> lg(m, boost::adopt_lock);
t1 = Clock::now();
}
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
#else
//time_point t0 = Clock::now();
//time_point t1;
@@ -64,22 +65,11 @@ int main()
m.lock();
boost::thread t(f);
#ifdef BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}

View File

@@ -30,8 +30,6 @@ typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#endif
boost::mutex m;
@@ -41,11 +39,14 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
#ifdef BOOST_THREAD_USES_CHRONO
t0 = Clock::now();
time_point t0 = Clock::now();
time_point t1;
{
boost::lock_guard<boost::mutex> lg(m);
t1 = Clock::now();
}
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
#else
//time_point t0 = Clock::now();
//time_point t1;
@@ -63,21 +64,10 @@ int main()
m.lock();
boost::thread t(f);
#ifdef BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}

View File

@@ -1,21 +0,0 @@
// Copyright (C) 2018 Tom Hughes
//
// 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)
// <boost/thread/lock_guard.hpp>
// template <class Mutex> class lock_guard;
// lock_guard(Mutex& m_, adopt_lock_t)
#include <boost/thread/lock_guard.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/detail/lightweight_test.hpp>
boost::mutex m;
void fail()
{
boost::lock_guard<boost::mutex> lk(m, boost::adopt_lock);
}

View File

@@ -1,22 +0,0 @@
// Copyright (C) 2018 Tom Hughes
//
// 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)
// <boost/thread/lock_guard.hpp>
// template <class Mutex> class lock_guard;
// lock_guard(Mutex& m_, adopt_lock_t)
#include <boost/thread/lock_guard.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/detail/lightweight_test.hpp>
boost::mutex m;
void pass()
{
m.lock();
boost::lock_guard<boost::mutex> lk(m, boost::adopt_lock);
}

View File

@@ -1,22 +0,0 @@
// Copyright (C) 2018 Tom Hughes
//
// 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)
// <boost/thread/lock_guard.hpp>
// template <class Mutex> class lock_guard;
// lock_guard(Mutex& m_)
#include <boost/thread/lock_guard.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/detail/lightweight_test.hpp>
boost::mutex m;
void fail()
{
boost::lock_guard<boost::mutex> lk0(m);
boost::lock_guard<boost::mutex> lk1(m);
}

View File

@@ -1,24 +0,0 @@
// Copyright (C) 2018 Tom Hughes
//
// 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)
// <boost/thread/lock_guard.hpp>
// template <class Mutex> class lock_guard;
// lock_guard(Mutex& m_)
#include <boost/thread/lock_guard.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/detail/lightweight_test.hpp>
boost::mutex m;
void pass()
{
{
boost::lock_guard<boost::mutex> lk0(m);
}
boost::lock_guard<boost::mutex> lk1(m);
}

View File

@@ -32,8 +32,6 @@ typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#endif
boost::mutex m;
@@ -44,13 +42,16 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
#ifdef BOOST_THREAD_USES_CHRONO
t0 = Clock::now();
time_point t0 = Clock::now();
time_point t1;
{
m.lock();
auto&& lg = boost::make_lock_guard(m, boost::adopt_lock); (void)lg;
t1 = Clock::now();
}
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
#else
//time_point t0 = Clock::now();
//time_point t1;
@@ -71,22 +72,10 @@ int main()
m.lock();
boost::thread t(f);
#ifdef BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
#endif
return boost::report_errors();
}

View File

@@ -32,8 +32,6 @@ typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#endif
boost::mutex m;
@@ -44,33 +42,27 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
t0 = Clock::now();
time_point t0 = Clock::now();
time_point t1;
{
const auto&& lg = boost::make_lock_guard(m); (void)lg;
t1 = Clock::now();
}
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
#endif
int main()
{
#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_THREAD_NO_MAKE_LOCK_GUARD && defined BOOST_THREAD_USES_CHRONO
#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_THREAD_NO_MAKE_LOCK_GUARD
{
m.lock();
boost::thread t(f);
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
m.unlock();
t.join();
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
}
#endif
return boost::report_errors();

View File

@@ -22,8 +22,6 @@ typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#endif
boost::mutex m;
@@ -33,12 +31,15 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
#ifdef BOOST_THREAD_USES_CHRONO
t0 = Clock::now();
time_point t0 = Clock::now();
time_point t1;
boost::unique_lock<boost::mutex> lg(m);
{
boost::nested_strict_lock<boost::unique_lock<boost::mutex> > nlg(lg);
t1 = Clock::now();
}
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
#else
//time_point t0 = Clock::now();
//time_point t1;
@@ -58,21 +59,10 @@ int main()
m.lock();
boost::thread t(f);
#ifdef BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
}
return boost::report_errors();

View File

@@ -24,8 +24,6 @@ typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#endif
boost::mutex m;
@@ -36,34 +34,28 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
t0 = Clock::now();
time_point t0 = Clock::now();
time_point t1;
boost::unique_lock<boost::mutex> lg(m);
{
const auto&& nlg = boost::make_nested_strict_lock(lg); (void)nlg;
t1 = Clock::now();
}
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
#endif
int main()
{
#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_THREAD_NO_MAKE_NESTED_STRICT_LOCK && defined BOOST_THREAD_USES_CHRONO
#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_THREAD_NO_MAKE_NESTED_STRICT_LOCK
{
m.lock();
boost::thread t(f);
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
m.unlock();
t.join();
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
}
#endif
return boost::report_errors();

View File

@@ -28,30 +28,30 @@
boost::shared_mutex m;
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f1()
{
t0 = Clock::now();
time_point t0 = Clock::now();
boost::shared_lock<boost::shared_mutex> lk(m, ms(750));
BOOST_TEST(lk.owns_lock() == true);
t1 = Clock::now();
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
void f2()
{
t0 = Clock::now();
time_point t0 = Clock::now();
boost::shared_lock<boost::shared_mutex> lk(m, ms(250));
BOOST_TEST(lk.owns_lock() == false);
t1 = Clock::now();
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
@@ -61,18 +61,9 @@ int main()
{
m.lock();
boost::thread t(f1);
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
m.unlock();
t.join();
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
}
{
m.lock();

View File

@@ -27,13 +27,11 @@
boost::shared_mutex m;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#else
#endif
@@ -42,11 +40,14 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
t0 = Clock::now();
time_point t0 = Clock::now();
time_point t1;
{
boost::shared_lock<boost::shared_mutex> ul(m);
t1 = Clock::now();
}
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
#else
//time_point t0 = Clock::now();
//time_point t1;
@@ -64,23 +65,12 @@ int main()
m.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#else
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}

View File

@@ -27,30 +27,30 @@
boost::shared_mutex m;
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f1()
{
t0 = Clock::now();
time_point t0 = Clock::now();
boost::shared_lock<boost::shared_mutex> lk(m, Clock::now() + ms(750));
BOOST_TEST(lk.owns_lock() == true);
t1 = Clock::now();
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
void f2()
{
t0 = Clock::now();
time_point t0 = Clock::now();
boost::shared_lock<boost::shared_mutex> lk(m, Clock::now() + ms(250));
BOOST_TEST(lk.owns_lock() == false);
t1 = Clock::now();
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
@@ -60,18 +60,9 @@ int main()
{
m.lock();
boost::thread t(f1);
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
m.unlock();
t.join();
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
}
{
m.lock();

View File

@@ -27,13 +27,11 @@
boost::shared_mutex m;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#else
#endif
@@ -42,7 +40,7 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
t0 = Clock::now();
time_point t0 = Clock::now();
{
boost::shared_lock<boost::shared_mutex> lk(m, boost::try_to_lock);
BOOST_TEST(lk.owns_lock() == false);
@@ -58,11 +56,11 @@ void f()
for (;;)
{
boost::shared_lock<boost::shared_mutex> lk(m, boost::try_to_lock);
if (lk.owns_lock()) {
t1 = Clock::now();
break;
}
if (lk.owns_lock()) break;
}
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
#else
// time_point t0 = Clock::now();
// {
@@ -93,23 +91,12 @@ int main()
m.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#else
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}

View File

@@ -28,13 +28,11 @@
boost::shared_mutex m;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#else
#endif
@@ -44,10 +42,12 @@ void f()
{
#if defined BOOST_THREAD_USES_CHRONO
boost::shared_lock < boost::shared_mutex > lk(m, boost::defer_lock);
t0 = Clock::now();
time_point t0 = Clock::now();
lk.lock();
t1 = Clock::now();
time_point t1 = Clock::now();
BOOST_TEST(lk.owns_lock() == true);
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
try
{
lk.lock();
@@ -104,23 +104,12 @@ int main()
m.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#else
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}

View File

@@ -30,8 +30,6 @@ typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#else
#endif
@@ -42,12 +40,15 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
t0 = Clock::now();
time_point t0 = Clock::now();
time_point t1;
{
m.lock_shared();
boost::shared_lock_guard<boost::shared_mutex> lg(m, boost::adopt_lock);
t1 = Clock::now();
}
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
#else
//time_point t0 = Clock::now();
//time_point t1;
@@ -66,23 +67,12 @@ int main()
m.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#else
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}

View File

@@ -31,8 +31,6 @@ typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#else
#endif
@@ -43,11 +41,14 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
t0 = Clock::now();
time_point t0 = Clock::now();
time_point t1;
{
boost::shared_lock_guard<boost::shared_mutex> lg(m);
t1 = Clock::now();
}
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
#else
//time_point t0 = Clock::now();
//time_point t1;
@@ -65,22 +66,11 @@ int main()
m.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#else
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}

View File

@@ -21,8 +21,6 @@ typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#endif
boost::mutex m;
@@ -32,11 +30,14 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
#ifdef BOOST_THREAD_USES_CHRONO
t0 = Clock::now();
time_point t0 = Clock::now();
time_point t1;
{
boost::strict_lock<boost::mutex> lg(m);
t1 = Clock::now();
}
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
#else
//time_point t0 = Clock::now();
//time_point t1;
@@ -54,21 +55,10 @@ int main()
m.lock();
boost::thread t(f);
#ifdef BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}

View File

@@ -23,8 +23,6 @@ typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#endif
boost::mutex m;
@@ -35,7 +33,8 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
t0 = Clock::now();
time_point t0 = Clock::now();
time_point t1;
{
const auto&& lg = boost::make_strict_lock(m); (void)lg;
t1 = Clock::now();
@@ -48,22 +47,13 @@ void f()
int main()
{
#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_THREAD_NO_MAKE_STRICT_LOCK && defined BOOST_THREAD_USES_CHRONO
#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && ! defined BOOST_THREAD_NO_MAKE_STRICT_LOCK
{
m.lock();
boost::thread t(f);
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
m.unlock();
t.join();
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
}
#endif
return boost::report_errors();

View File

@@ -32,32 +32,32 @@
boost::timed_mutex m;
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f1()
{
t0 = Clock::now();
time_point t0 = Clock::now();
boost::unique_lock<boost::timed_mutex> lk(m, ms(750));
BOOST_TEST(lk.owns_lock() == true);
t1 = Clock::now();
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
void f2()
{
t0 = Clock::now();
time_point t0 = Clock::now();
boost::unique_lock<boost::timed_mutex> lk(m, ms(250));
BOOST_TEST(lk.owns_lock() == false);
t1 = Clock::now();
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
BOOST_TEST(d < max_diff);
}
int main()
@@ -65,18 +65,9 @@ int main()
{
m.lock();
boost::thread t(f1);
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
m.unlock();
t.join();
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
}
{
m.lock();

View File

@@ -23,13 +23,11 @@ boost::mutex m;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#else
#endif
@@ -38,7 +36,8 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
t0 = Clock::now();
time_point t0 = Clock::now();
time_point t1;
{
#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS)
auto
@@ -49,6 +48,8 @@ void f()
_ = boost::make_unique_lock(m); (void)_;
t1 = Clock::now();
}
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
#else
//time_point t0 = Clock::now();
//time_point t1;
@@ -72,23 +73,12 @@ int main()
m.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#else
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}
//#else

View File

@@ -20,13 +20,11 @@
boost::mutex m;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#else
#endif
@@ -36,7 +34,7 @@ void f()
{
#if defined BOOST_THREAD_USES_CHRONO
{
t0 = Clock::now();
time_point t0 = Clock::now();
#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS)
auto
#else
@@ -44,12 +42,12 @@ void f()
#endif
lk = boost::make_unique_lock(m, boost::try_to_lock);
BOOST_TEST(lk.owns_lock() == false);
t1 = Clock::now();
ns d = t1 - t0;
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
{
t0 = Clock::now();
time_point t0 = Clock::now();
#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS)
auto
#else
@@ -57,12 +55,12 @@ void f()
#endif
lk = boost::make_unique_lock(m, boost::try_to_lock);
BOOST_TEST(lk.owns_lock() == false);
t1 = Clock::now();
ns d = t1 - t0;
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
{
t0 = Clock::now();
time_point t0 = Clock::now();
#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS)
auto
#else
@@ -70,12 +68,12 @@ void f()
#endif
lk = boost::make_unique_lock(m, boost::try_to_lock);
BOOST_TEST(lk.owns_lock() == false);
t1 = Clock::now();
ns d = t1 - t0;
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
{
t0 = Clock::now();
time_point t0 = Clock::now();
for (;;)
{
#if ! defined(BOOST_NO_CXX11_AUTO_DECLARATIONS)
@@ -84,11 +82,11 @@ void f()
boost::unique_lock<boost::mutex>
#endif
lk = boost::make_unique_lock(m, boost::try_to_lock);
if (lk.owns_lock()) {
t1 = Clock::now();
break;
}
if (lk.owns_lock()) break;
}
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
#else
// time_point t0 = Clock::now();
@@ -125,22 +123,11 @@ int main()
m.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#else
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}

View File

@@ -25,13 +25,11 @@ boost::mutex m3;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#else
#endif
@@ -40,11 +38,14 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
t0 = Clock::now();
time_point t0 = Clock::now();
time_point t1;
{
auto&& _ = boost::make_unique_locks(m1,m2,m3); (void)_;
t1 = Clock::now();
}
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
#else
//time_point t0 = Clock::now();
//time_point t1;
@@ -64,9 +65,7 @@ int main()
m3.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#else
#endif
m1.unlock();
@@ -74,15 +73,6 @@ int main()
m3.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}
#else

View File

@@ -30,13 +30,11 @@
boost::mutex m;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#else
#endif
@@ -45,11 +43,14 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
t0 = Clock::now();
time_point t0 = Clock::now();
time_point t1;
{
boost::unique_lock<boost::mutex> ul(m);
t1 = Clock::now();
}
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
#else
//time_point t0 = Clock::now();
//time_point t1;
@@ -67,23 +68,12 @@ int main()
m.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#else
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}

View File

@@ -31,30 +31,30 @@
boost::timed_mutex m;
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f1()
{
t0 = Clock::now();
time_point t0 = Clock::now();
boost::unique_lock<boost::timed_mutex> lk(m, Clock::now() + ms(750));
BOOST_TEST(lk.owns_lock() == true);
t1 = Clock::now();
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
void f2()
{
t0 = Clock::now();
time_point t0 = Clock::now();
boost::unique_lock<boost::timed_mutex> lk(m, Clock::now() + ms(250));
BOOST_TEST(lk.owns_lock() == false);
t1 = Clock::now();
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
BOOST_TEST(d < max_diff);
}
@@ -64,18 +64,9 @@ int main()
{
m.lock();
boost::thread t(f1);
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
m.unlock();
t.join();
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
}
{
m.lock();

View File

@@ -29,13 +29,11 @@
boost::mutex m;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#else
#endif
@@ -44,7 +42,7 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
t0 = Clock::now();
time_point t0 = Clock::now();
{
boost::unique_lock<boost::mutex> lk(m, boost::try_to_lock);
BOOST_TEST(lk.owns_lock() == false);
@@ -60,12 +58,12 @@ void f()
for (;;)
{
boost::unique_lock<boost::mutex> lk(m, boost::try_to_lock);
if (lk.owns_lock()) {
t1 = Clock::now();
break;
}
if (lk.owns_lock()) break;
}
time_point t1 = Clock::now();
//m.unlock();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
#else
// time_point t0 = Clock::now();
// {
@@ -96,25 +94,12 @@ int main()
m.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#else
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
std::cout << "d_ns: " << d_ns.count() << std::endl;
std::cout << "d_ms: " << d_ms.count() << std::endl;
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}

View File

@@ -28,13 +28,11 @@
boost::mutex m;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#else
#endif
@@ -44,10 +42,12 @@ void f()
{
#if defined BOOST_THREAD_USES_CHRONO
boost::unique_lock < boost::mutex > lk(m, boost::defer_lock);
t0 = Clock::now();
time_point t0 = Clock::now();
lk.lock();
t1 = Clock::now();
time_point t1 = Clock::now();
BOOST_TEST(lk.owns_lock() == true);
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
try
{
lk.lock();
@@ -104,23 +104,12 @@ int main()
m.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#else
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}

View File

@@ -30,30 +30,30 @@
boost::shared_mutex m;
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f1()
{
t0 = Clock::now();
time_point t0 = Clock::now();
boost::upgrade_lock<boost::shared_mutex> lk(m, ms(750));
BOOST_TEST(lk.owns_lock() == true);
t1 = Clock::now();
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
void f2()
{
t0 = Clock::now();
time_point t0 = Clock::now();
boost::upgrade_lock<boost::shared_mutex> lk(m, ms(250));
BOOST_TEST(lk.owns_lock() == false);
t1 = Clock::now();
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
@@ -63,18 +63,9 @@ int main()
{
m.lock();
boost::thread t(f1);
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
m.unlock();
t.join();
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
}
{
m.lock();

View File

@@ -29,13 +29,11 @@
boost::shared_mutex m;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#else
#endif
@@ -44,11 +42,16 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
t0 = Clock::now();
time_point t0 = Clock::now();
time_point t1;
{
boost::upgrade_lock<boost::shared_mutex> ul(m);
t1 = Clock::now();
}
ns d = t1 - t0 - ms(250);
std::cout << "diff= " << d.count() << std::endl;
std::cout << "max_diff= " << max_diff.count() << std::endl;
BOOST_THREAD_TEST_IT(d, ns(max_diff));
#else
//time_point t0 = Clock::now();
//time_point t1;
@@ -66,23 +69,12 @@ int main()
m.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#else
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}

View File

@@ -29,30 +29,30 @@
boost::shared_mutex m;
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f1()
{
t0 = Clock::now();
time_point t0 = Clock::now();
boost::upgrade_lock<boost::shared_mutex> lk(m, Clock::now() + ms(750));
BOOST_TEST(lk.owns_lock() == true);
t1 = Clock::now();
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
void f2()
{
t0 = Clock::now();
time_point t0 = Clock::now();
boost::upgrade_lock<boost::shared_mutex> lk(m, Clock::now() + ms(250));
BOOST_TEST(lk.owns_lock() == false);
t1 = Clock::now();
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
@@ -62,18 +62,9 @@ int main()
{
m.lock();
boost::thread t(f1);
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
m.unlock();
t.join();
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
}
{
m.lock();

View File

@@ -28,13 +28,11 @@
boost::shared_mutex m;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#else
#endif
@@ -43,7 +41,7 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
t0 = Clock::now();
time_point t0 = Clock::now();
{
boost::upgrade_lock<boost::shared_mutex> lk(m, boost::try_to_lock);
BOOST_TEST(lk.owns_lock() == false);
@@ -59,12 +57,12 @@ void f()
for (;;)
{
boost::upgrade_lock<boost::shared_mutex> lk(m, boost::try_to_lock);
if (lk.owns_lock()) {
t1 = Clock::now();
break;
}
if (lk.owns_lock()) break;
}
time_point t1 = Clock::now();
//m.unlock();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
#else
// time_point t0 = Clock::now();
// {
@@ -95,23 +93,12 @@ int main()
m.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#else
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}

View File

@@ -28,13 +28,11 @@
boost::shared_mutex m;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#else
#endif
@@ -44,10 +42,12 @@ void f()
{
#if defined BOOST_THREAD_USES_CHRONO
boost::upgrade_lock < boost::shared_mutex > lk(m, boost::defer_lock);
t0 = Clock::now();
time_point t0 = Clock::now();
lk.lock();
t1 = Clock::now();
time_point t1 = Clock::now();
BOOST_TEST(lk.owns_lock() == true);
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
try
{
lk.lock();
@@ -104,23 +104,12 @@ int main()
m.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#else
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}

View File

@@ -1,19 +0,0 @@
// Copyright (C) 2017 Tom Hughes
//
// 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)
// <boost/thread/mutex.hpp>
// class mutex;
#include <boost/thread/mutex.hpp>
#include <boost/detail/lightweight_test.hpp>
void fail()
{
boost::mutex m0;
m0.lock();
m0.lock();
m0.unlock();
}

View File

@@ -1,18 +0,0 @@
// Copyright (C) 2017 Tom Hughes
//
// 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)
// <boost/thread/mutex.hpp>
// class mutex;
#include <boost/thread/mutex.hpp>
#include <boost/detail/lightweight_test.hpp>
void pass()
{
boost::mutex m0;
m0.lock();
m0.unlock();
}

View File

@@ -26,13 +26,11 @@
boost::mutex m;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#else
#endif
@@ -41,10 +39,12 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
t0 = Clock::now();
time_point t0 = Clock::now();
m.lock();
t1 = Clock::now();
time_point t1 = Clock::now();
m.unlock();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
#else
//time_point t0 = Clock::now();
m.lock();
@@ -60,22 +60,11 @@ int main()
m.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}

View File

@@ -1,19 +0,0 @@
// Copyright (C) 2017 Tom Hughes
//
// 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)
// <boost/thread/mutex.hpp>
// class mutex;
#include <boost/thread/mutex.hpp>
#include <boost/detail/lightweight_test.hpp>
void fail()
{
boost::mutex m0;
if (!m0.try_lock()) {
m0.unlock();
}
}

View File

@@ -1,19 +0,0 @@
// Copyright (C) 2017 Tom Hughes
//
// 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)
// <boost/thread/mutex.hpp>
// class mutex;
#include <boost/thread/mutex.hpp>
#include <boost/detail/lightweight_test.hpp>
void pass()
{
boost::mutex m0;
if (m0.try_lock()) {
m0.unlock();
}
}

View File

@@ -27,13 +27,11 @@
boost::mutex m;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#endif
const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
@@ -41,14 +39,16 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
t0 = Clock::now();
time_point t0 = Clock::now();
BOOST_TEST(!m.try_lock());
BOOST_TEST(!m.try_lock());
BOOST_TEST(!m.try_lock());
while (!m.try_lock())
;
t1 = Clock::now();
time_point t1 = Clock::now();
m.unlock();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
#else
//time_point t0 = Clock::now();
//BOOST_TEST(!m.try_lock());
@@ -69,22 +69,11 @@ int main()
m.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}

View File

@@ -26,7 +26,7 @@
boost::null_mutex m;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;

View File

@@ -29,7 +29,7 @@
boost::null_mutex m;
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;

View File

@@ -28,7 +28,7 @@
boost::null_mutex m;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;

View File

@@ -27,13 +27,11 @@
boost::recursive_mutex m;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#else
#endif
@@ -42,12 +40,14 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
t0 = Clock::now();
time_point t0 = Clock::now();
m.lock();
t1 = Clock::now();
time_point t1 = Clock::now();
m.lock();
m.unlock();
m.unlock();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
#else
//time_point t0 = Clock::now();
m.lock();
@@ -65,23 +65,12 @@ int main()
m.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#else
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}

View File

@@ -27,13 +27,11 @@
boost::recursive_mutex m;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#else
#endif
@@ -42,16 +40,18 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
t0 = Clock::now();
time_point t0 = Clock::now();
// BOOST_TEST(!m.try_lock());
// BOOST_TEST(!m.try_lock());
// BOOST_TEST(!m.try_lock());
while (!m.try_lock())
;
t1 = Clock::now();
time_point t1 = Clock::now();
BOOST_TEST(m.try_lock());
m.unlock();
m.unlock();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
#else
//time_point t0 = Clock::now();
//BOOST_TEST(!m.try_lock());
@@ -73,23 +73,12 @@ int main()
m.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#else
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}

View File

@@ -27,13 +27,11 @@
boost::recursive_timed_mutex m;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#else
#endif
@@ -42,12 +40,14 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
t0 = Clock::now();
time_point t0 = Clock::now();
m.lock();
t1 = Clock::now();
time_point t1 = Clock::now();
m.lock();
m.unlock();
m.unlock();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
#else
//time_point t0 = Clock::now();
m.lock();
@@ -65,23 +65,12 @@ int main()
m.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#else
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}

View File

@@ -28,24 +28,24 @@
boost::recursive_timed_mutex m;
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f1()
{
t0 = Clock::now();
time_point t0 = Clock::now();
BOOST_TEST(m.try_lock_for(ms(750)) == true);
t1 = Clock::now();
time_point t1 = Clock::now();
BOOST_TEST(m.try_lock());
m.unlock();
m.unlock();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
void f2()
@@ -62,18 +62,9 @@ int main()
{
m.lock();
boost::thread t(f1);
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
m.unlock();
t.join();
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
}
{
m.lock();

View File

@@ -26,13 +26,11 @@
boost::recursive_timed_mutex m;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#else
#endif
@@ -41,16 +39,18 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
t0 = Clock::now();
time_point t0 = Clock::now();
BOOST_TEST(!m.try_lock());
BOOST_TEST(!m.try_lock());
BOOST_TEST(!m.try_lock());
while (!m.try_lock())
;
t1 = Clock::now();
time_point t1 = Clock::now();
BOOST_TEST(m.try_lock());
m.unlock();
m.unlock();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
#else
//time_point t0 = Clock::now();
//BOOST_TEST(!m.try_lock());
@@ -72,23 +72,12 @@ int main()
m.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#else
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}

View File

@@ -28,29 +28,29 @@
boost::recursive_timed_mutex m;
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f1()
{
t0 = Clock::now();
time_point t0 = Clock::now();
BOOST_TEST(m.try_lock_until(Clock::now() + ms(750)) == true);
t1 = Clock::now();
time_point t1 = Clock::now();
m.unlock();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
void f2()
{
t0 = Clock::now();
time_point t0 = Clock::now();
BOOST_TEST(m.try_lock_until(Clock::now() + ms(250)) == false);
t1 = Clock::now();
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
@@ -60,20 +60,9 @@ int main()
{
m.lock();
boost::thread t(f1);
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
}
{
m.lock();

View File

@@ -26,13 +26,11 @@
boost::shared_mutex m;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#else
#endif
@@ -41,10 +39,12 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
t0 = Clock::now();
time_point t0 = Clock::now();
m.lock();
t1 = Clock::now();
time_point t1 = Clock::now();
m.unlock();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
#else
//time_point t0 = Clock::now();
m.lock();
@@ -60,23 +60,12 @@ int main()
m.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#else
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}

View File

@@ -26,29 +26,29 @@
boost::shared_mutex m;
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f1()
{
t0 = Clock::now();
time_point t0 = Clock::now();
BOOST_TEST(m.try_lock_for(ms(750)) == true);
t1 = Clock::now();
time_point t1 = Clock::now();
m.unlock();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
void f2()
{
t0 = Clock::now();
time_point t0 = Clock::now();
BOOST_TEST(m.try_lock_for(ms(250)) == false);
t1 = Clock::now();
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
@@ -58,20 +58,9 @@ int main()
{
m.lock();
boost::thread t(f1);
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
}
{
m.lock();

View File

@@ -26,13 +26,11 @@
boost::shared_mutex m;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#else
#endif
@@ -41,14 +39,16 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
t0 = Clock::now();
time_point t0 = Clock::now();
BOOST_TEST(!m.try_lock());
BOOST_TEST(!m.try_lock());
BOOST_TEST(!m.try_lock());
while (!m.try_lock())
;
t1 = Clock::now();
time_point t1 = Clock::now();
m.unlock();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
#else
//time_point t0 = Clock::now();
//BOOST_TEST(!m.try_lock());
@@ -68,23 +68,12 @@ int main()
m.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#else
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}

View File

@@ -26,29 +26,29 @@
boost::shared_mutex m;
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f1()
{
t0 = Clock::now();
time_point t0 = Clock::now();
BOOST_TEST(m.try_lock_until(Clock::now() + ms(750)) == true);
t1 = Clock::now();
time_point t1 = Clock::now();
m.unlock();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
void f2()
{
t0 = Clock::now();
time_point t0 = Clock::now();
BOOST_TEST(m.try_lock_until(Clock::now() + ms(250)) == false);
t1 = Clock::now();
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
@@ -58,18 +58,9 @@ int main()
{
m.lock();
boost::thread t(f1);
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
m.unlock();
t.join();
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
}
{
m.lock();

View File

@@ -26,13 +26,11 @@
boost::timed_mutex m;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#else
#endif
@@ -41,10 +39,12 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
t0 = Clock::now();
time_point t0 = Clock::now();
m.lock();
t1 = Clock::now();
time_point t1 = Clock::now();
m.unlock();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
#else
//time_point t0 = Clock::now();
m.lock();
@@ -60,23 +60,12 @@ int main()
m.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#else
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}

View File

@@ -28,29 +28,29 @@
boost::timed_mutex m;
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f1()
{
t0 = Clock::now();
time_point t0 = Clock::now();
BOOST_TEST(m.try_lock_for(ms(750)) == true);
t1 = Clock::now();
time_point t1 = Clock::now();
m.unlock();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
void f2()
{
t0 = Clock::now();
time_point t0 = Clock::now();
BOOST_TEST(m.try_lock_for(ms(250)) == false);
t1 = Clock::now();
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
@@ -60,18 +60,9 @@ int main()
{
m.lock();
boost::thread t(f1);
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
m.unlock();
t.join();
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
}
{
m.lock();

View File

@@ -27,13 +27,11 @@
boost::timed_mutex m;
#if defined BOOST_THREAD_USES_CHRONO
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
#else
#endif
@@ -42,14 +40,16 @@ const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
t0 = Clock::now();
time_point t0 = Clock::now();
BOOST_TEST(!m.try_lock());
BOOST_TEST(!m.try_lock());
BOOST_TEST(!m.try_lock());
while (!m.try_lock())
;
t1 = Clock::now();
time_point t1 = Clock::now();
m.unlock();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
#else
//time_point t0 = Clock::now();
//BOOST_TEST(!m.try_lock());
@@ -69,23 +69,12 @@ int main()
m.lock();
boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
#else
#endif
m.unlock();
t.join();
#if defined BOOST_THREAD_USES_CHRONO
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif
return boost::report_errors();
}

View File

@@ -28,29 +28,29 @@
boost::timed_mutex m;
typedef boost::chrono::high_resolution_clock Clock;
typedef boost::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
time_point t0;
time_point t1;
const ms max_diff(BOOST_THREAD_TEST_TIME_MS);
void f1()
{
t0 = Clock::now();
time_point t0 = Clock::now();
BOOST_TEST(m.try_lock_until(Clock::now() + ms(750)) == true);
t1 = Clock::now();
time_point t1 = Clock::now();
m.unlock();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
void f2()
{
t0 = Clock::now();
time_point t0 = Clock::now();
BOOST_TEST(m.try_lock_until(Clock::now() + ms(250)) == false);
t1 = Clock::now();
time_point t1 = Clock::now();
ns d = t1 - t0 - ms(250);
BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
@@ -60,18 +60,9 @@ int main()
{
m.lock();
boost::thread t(f1);
time_point t2 = Clock::now();
boost::this_thread::sleep_for(ms(250));
time_point t3 = Clock::now();
m.unlock();
t.join();
ns sleep_time = t3 - t2;
ns d_ns = t1 - t0 - sleep_time;
ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
// BOOST_TEST_GE(d_ms.count(), 0);
BOOST_THREAD_TEST_IT(d_ms, max_diff);
BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
}
{
m.lock();

View File

@@ -1,17 +0,0 @@
// Copyright (C) 2018 Vicente Botet
//
// 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 4
#include <boost/thread/detail/nullary_function.hpp>
#include <boost/system/detail/error_code.ipp>
int main(int argc, char* argv[])
{
boost::detail::nullary_function<void ()> f1;
auto f2 = f1;
}

View File

@@ -1,5 +1,5 @@
#ifdef _WIN32
#include <Windows.h>
#include <windows.h>
#else
#include <sys/time.h>
#endif