mirror of
https://github.com/boostorg/thread.git
synced 2026-01-24 06:22:12 +00:00
https://svn.boost.org/svn/boost/trunk ........ r41679 | anthonyw | 2007-12-03 23:57:23 -0800 (Mon, 03 Dec 2007) | 1 line fixed typo in condition_variable_any::timed_wait ........ r41681 | anthonyw | 2007-12-04 01:15:37 -0800 (Tue, 04 Dec 2007) | 1 line changed boost::move to boost::detail::thread_move to fix issue #1492 ........ r41682 | anthonyw | 2007-12-04 02:04:30 -0800 (Tue, 04 Dec 2007) | 1 line split shared mutex tests in two to take less time ........ r41683 | anthonyw | 2007-12-04 03:44:25 -0800 (Tue, 04 Dec 2007) | 1 line don't dllexport/dllimport inline functions ........ r41684 | anthonyw | 2007-12-04 04:08:38 -0800 (Tue, 04 Dec 2007) | 1 line add explicit casts to remove warnings ........ r41686 | anthonyw | 2007-12-04 05:02:58 -0800 (Tue, 04 Dec 2007) | 1 line Added test for thread move constructor; implemented move on pthreads ........ r41687 | anthonyw | 2007-12-04 06:07:01 -0800 (Tue, 04 Dec 2007) | 1 line changed order of declaration to eliminate warnings ........ r41688 | nesotto | 2007-12-04 06:41:44 -0800 (Tue, 04 Dec 2007) | 1 line ticket 1488 ........ r41696 | fmhess | 2007-12-04 11:42:08 -0800 (Tue, 04 Dec 2007) | 2 lines Make sure output filenames don't include any illegal characters. ........ r41697 | fmhess | 2007-12-04 11:45:10 -0800 (Tue, 04 Dec 2007) | 4 lines Fixed printing of object name for nested classes (merge of revision 41421 from sandbox/boost_docs). ........ r41698 | fmhess | 2007-12-04 11:55:50 -0800 (Tue, 04 Dec 2007) | 17 lines Made generated ids for functions and overloaded functions human-readable which also results in (mostly) human-readable names for their .html output files. Made generate.id template properly use its node parameter (merge of parts of revision 41461 from sandbox/boost_docs). Made class name in synopsis a link to class reference page, which is useful for nested classes (merge of revision 41435 from sandbox/boost_docs). Removed spurious new line in synopisis between a nested class and the comment describing its purpose (merge of revision 41434 from sandbox/boost_docs). Added a warning if an "inherit" element has no "type" child element (partial merge of revision 41463 from sandbox/boost_docs). ........ r41701 | chris_kohlhoff | 2007-12-04 13:28:42 -0800 (Tue, 04 Dec 2007) | 2 lines Prevent deprecated function warnings for MSVC >= 8. ........ r41703 | nasonov | 2007-12-04 13:49:51 -0800 (Tue, 04 Dec 2007) | 1 line Link to html version of [Tuning] and BOOST_LEXICAL_CAST_ASSUME_C_LOCALE synopsis ........ r41704 | igaztanaga | 2007-12-04 14:05:28 -0800 (Tue, 04 Dec 2007) | 1 line Added Leopard workaround. _POSIX_THREAD_PROCESS_SHARED is defined but does not seem to work. For the moment, Mac OS will use emulation code ........ r41705 | djenkins | 2007-12-04 14:19:58 -0800 (Tue, 04 Dec 2007) | 1 line Fix msvc-9.0 code analysis problem ........ r41707 | noel_belcourt | 2007-12-04 15:18:38 -0800 (Tue, 04 Dec 2007) | 6 lines Fixes to get pgi shared libraries working, executables that don't core, and limiting the number of error messages emitted by the compiler so as to reduce the size of the log file. ........ r41727 | grafik | 2007-12-04 16:32:04 -0800 (Tue, 04 Dec 2007) | 1 line Switch FTP site for results. ........ r41734 | noel_belcourt | 2007-12-04 19:11:25 -0800 (Tue, 04 Dec 2007) | 5 lines Pgi compilers can't accept shared library with Boost version suffix appended to it. Add logic to tag rule in Jamroot to suppress appending version suffix for pgi toolset. ........ r41735 | noel_belcourt | 2007-12-04 19:20:30 -0800 (Tue, 04 Dec 2007) | 3 lines Patch pgi shared library use. ........ r41736 | grafik | 2007-12-04 20:33:36 -0800 (Tue, 04 Dec 2007) | 1 line Fix parsing of macosx version numbers from detected SDKs. ........ r41738 | anthonyw | 2007-12-05 00:27:44 -0800 (Wed, 05 Dec 2007) | 1 line added missing include of detail/config.hpp ........ r41739 | t_schwinger | 2007-12-05 02:24:21 -0800 (Wed, 05 Dec 2007) | 3 lines clarifies #error message ........ r41740 | t_schwinger | 2007-12-05 02:26:16 -0800 (Wed, 05 Dec 2007) | 2 lines updates function_types failures ........ r41741 | anthonyw | 2007-12-05 02:58:45 -0800 (Wed, 05 Dec 2007) | 1 line improved timeout checks ........ r41742 | t_schwinger | 2007-12-05 05:20:13 -0800 (Wed, 05 Dec 2007) | 3 lines attempts to fix strange problems with Pathscale compilers ........ r41762 | chris_kohlhoff | 2007-12-05 13:46:19 -0800 (Wed, 05 Dec 2007) | 2 lines Don't use deprecated function workaround when compiling for Windows CE. ........ r41770 | ramey | 2007-12-05 18:33:59 -0800 (Wed, 05 Dec 2007) | 2 lines change to fix failures with gcc 4.1+ modification to string input primitives ........ r41775 | djenkins | 2007-12-05 22:23:55 -0800 (Wed, 05 Dec 2007) | 1 line Avoid bug in Microsoft Code Analysis ........ [SVN r41776]
253 lines
6.6 KiB
C++
253 lines
6.6 KiB
C++
// Copyright (C) 2001-2003
|
|
// William E. Kempf
|
|
//
|
|
// 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)
|
|
|
|
#include <boost/thread/detail/config.hpp>
|
|
|
|
#include <boost/thread/mutex.hpp>
|
|
#include <boost/thread/recursive_mutex.hpp>
|
|
#include <boost/thread/thread_time.hpp>
|
|
#include <boost/thread/condition.hpp>
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
#define DEFAULT_EXECUTION_MONITOR_TYPE execution_monitor::use_sleep_only
|
|
#include <libs/thread/test/util.inl>
|
|
|
|
template <typename M>
|
|
struct test_lock
|
|
{
|
|
typedef M mutex_type;
|
|
typedef typename M::scoped_lock lock_type;
|
|
|
|
void operator()()
|
|
{
|
|
mutex_type mutex;
|
|
boost::condition condition;
|
|
|
|
// Test the lock's constructors.
|
|
{
|
|
lock_type lock(mutex, boost::defer_lock);
|
|
BOOST_CHECK(!lock);
|
|
}
|
|
lock_type lock(mutex);
|
|
BOOST_CHECK(lock ? true : false);
|
|
|
|
// Construct and initialize an xtime for a fast time out.
|
|
boost::xtime xt = delay(0, 100);
|
|
|
|
// Test the lock and the mutex with condition variables.
|
|
// No one is going to notify this condition variable. We expect to
|
|
// time out.
|
|
BOOST_CHECK(!condition.timed_wait(lock, xt));
|
|
BOOST_CHECK(lock ? true : false);
|
|
|
|
// Test the lock and unlock methods.
|
|
lock.unlock();
|
|
BOOST_CHECK(!lock);
|
|
lock.lock();
|
|
BOOST_CHECK(lock ? true : false);
|
|
}
|
|
};
|
|
|
|
template <typename M>
|
|
struct test_trylock
|
|
{
|
|
typedef M mutex_type;
|
|
typedef typename M::scoped_try_lock try_lock_type;
|
|
|
|
void operator()()
|
|
{
|
|
mutex_type mutex;
|
|
boost::condition condition;
|
|
|
|
// Test the lock's constructors.
|
|
{
|
|
try_lock_type lock(mutex);
|
|
BOOST_CHECK(lock ? true : false);
|
|
}
|
|
{
|
|
try_lock_type lock(mutex, boost::defer_lock);
|
|
BOOST_CHECK(!lock);
|
|
}
|
|
try_lock_type lock(mutex);
|
|
BOOST_CHECK(lock ? true : false);
|
|
|
|
// Construct and initialize an xtime for a fast time out.
|
|
boost::xtime xt = delay(0, 100);
|
|
|
|
// Test the lock and the mutex with condition variables.
|
|
// No one is going to notify this condition variable. We expect to
|
|
// time out.
|
|
BOOST_CHECK(!condition.timed_wait(lock, xt));
|
|
BOOST_CHECK(lock ? true : false);
|
|
|
|
// Test the lock, unlock and trylock methods.
|
|
lock.unlock();
|
|
BOOST_CHECK(!lock);
|
|
lock.lock();
|
|
BOOST_CHECK(lock ? true : false);
|
|
lock.unlock();
|
|
BOOST_CHECK(!lock);
|
|
BOOST_CHECK(lock.try_lock());
|
|
BOOST_CHECK(lock ? true : false);
|
|
}
|
|
};
|
|
|
|
template <typename M>
|
|
struct test_timedlock
|
|
{
|
|
typedef M mutex_type;
|
|
typedef typename M::scoped_timed_lock timed_lock_type;
|
|
|
|
static bool fake_predicate()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
void operator()()
|
|
{
|
|
mutex_type mutex;
|
|
boost::condition condition;
|
|
|
|
// Test the lock's constructors.
|
|
{
|
|
// Construct and initialize an xtime for a fast time out.
|
|
boost::system_time xt = boost::get_system_time()+boost::posix_time::milliseconds(100);
|
|
|
|
timed_lock_type lock(mutex, xt);
|
|
BOOST_CHECK(lock ? true : false);
|
|
}
|
|
{
|
|
timed_lock_type lock(mutex, boost::defer_lock);
|
|
BOOST_CHECK(!lock);
|
|
}
|
|
timed_lock_type lock(mutex);
|
|
BOOST_CHECK(lock ? true : false);
|
|
|
|
// Construct and initialize an xtime for a fast time out.
|
|
boost::system_time timeout = boost::get_system_time()+boost::posix_time::milliseconds(100);
|
|
|
|
// Test the lock and the mutex with condition variables.
|
|
// No one is going to notify this condition variable. We expect to
|
|
// time out.
|
|
BOOST_CHECK(!condition.timed_wait(lock, timeout, fake_predicate));
|
|
BOOST_CHECK(lock ? true : false);
|
|
|
|
boost::system_time now=boost::get_system_time();
|
|
boost::posix_time::milliseconds const timeout_resolution(20);
|
|
BOOST_CHECK((now-timeout_resolution)<timeout);
|
|
|
|
// Test the lock, unlock and timedlock methods.
|
|
lock.unlock();
|
|
BOOST_CHECK(!lock);
|
|
lock.lock();
|
|
BOOST_CHECK(lock ? true : false);
|
|
lock.unlock();
|
|
BOOST_CHECK(!lock);
|
|
boost::system_time target = boost::get_system_time()+boost::posix_time::milliseconds(100);
|
|
BOOST_CHECK(lock.timed_lock(target));
|
|
BOOST_CHECK(lock ? true : false);
|
|
}
|
|
};
|
|
|
|
template <typename M>
|
|
struct test_recursive_lock
|
|
{
|
|
typedef M mutex_type;
|
|
typedef typename M::scoped_lock lock_type;
|
|
|
|
void operator()()
|
|
{
|
|
mutex_type mx;
|
|
lock_type lock1(mx);
|
|
lock_type lock2(mx);
|
|
}
|
|
};
|
|
|
|
void do_test_mutex()
|
|
{
|
|
test_lock<boost::mutex>()();
|
|
}
|
|
|
|
void test_mutex()
|
|
{
|
|
timed_test(&do_test_mutex, 3);
|
|
}
|
|
|
|
void do_test_try_mutex()
|
|
{
|
|
test_lock<boost::try_mutex>()();
|
|
test_trylock<boost::try_mutex>()();
|
|
}
|
|
|
|
void test_try_mutex()
|
|
{
|
|
timed_test(&do_test_try_mutex, 3);
|
|
}
|
|
|
|
void do_test_timed_mutex()
|
|
{
|
|
test_lock<boost::timed_mutex>()();
|
|
test_trylock<boost::timed_mutex>()();
|
|
test_timedlock<boost::timed_mutex>()();
|
|
}
|
|
|
|
void test_timed_mutex()
|
|
{
|
|
timed_test(&do_test_timed_mutex, 3);
|
|
}
|
|
|
|
void do_test_recursive_mutex()
|
|
{
|
|
test_lock<boost::recursive_mutex>()();
|
|
test_recursive_lock<boost::recursive_mutex>()();
|
|
}
|
|
|
|
void test_recursive_mutex()
|
|
{
|
|
timed_test(&do_test_recursive_mutex, 3);
|
|
}
|
|
|
|
void do_test_recursive_try_mutex()
|
|
{
|
|
test_lock<boost::recursive_try_mutex>()();
|
|
test_trylock<boost::recursive_try_mutex>()();
|
|
test_recursive_lock<boost::recursive_try_mutex>()();
|
|
}
|
|
|
|
void test_recursive_try_mutex()
|
|
{
|
|
timed_test(&do_test_recursive_try_mutex, 3);
|
|
}
|
|
|
|
void do_test_recursive_timed_mutex()
|
|
{
|
|
test_lock<boost::recursive_timed_mutex>()();
|
|
test_trylock<boost::recursive_timed_mutex>()();
|
|
test_timedlock<boost::recursive_timed_mutex>()();
|
|
test_recursive_lock<boost::recursive_timed_mutex>()();
|
|
}
|
|
|
|
void test_recursive_timed_mutex()
|
|
{
|
|
timed_test(&do_test_recursive_timed_mutex, 3);
|
|
}
|
|
|
|
boost::unit_test_framework::test_suite* init_unit_test_suite(int, char*[])
|
|
{
|
|
boost::unit_test_framework::test_suite* test =
|
|
BOOST_TEST_SUITE("Boost.Threads: mutex test suite");
|
|
|
|
test->add(BOOST_TEST_CASE(&test_mutex));
|
|
test->add(BOOST_TEST_CASE(&test_try_mutex));
|
|
test->add(BOOST_TEST_CASE(&test_timed_mutex));
|
|
test->add(BOOST_TEST_CASE(&test_recursive_mutex));
|
|
test->add(BOOST_TEST_CASE(&test_recursive_try_mutex));
|
|
test->add(BOOST_TEST_CASE(&test_recursive_timed_mutex));
|
|
|
|
return test;
|
|
}
|