Skip to content

Commit

Permalink
Thread: merge from trunk 1.54 - once_atomic; null_mutex
Browse files Browse the repository at this point in the history
[SVN r82838]
  • Loading branch information
viboes committed Feb 12, 2013
1 parent 8416d3e commit f9b257e
Show file tree
Hide file tree
Showing 59 changed files with 3,928 additions and 488 deletions.
9 changes: 7 additions & 2 deletions build/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,11 @@ rule usage-requirements ( properties * )
}
}

if ! <toolset>vacpp in $(properties) || <toolset-vacpp:version>11.1 in $(properties) || <toolset-vacpp:version>12.1.0.1 in $(properties)
if ! <toolset>vacpp in $(properties) || <toolset-vacpp:version>11.1 in $(properties) || <toolset-vacpp:version>12.1.0.1 in $(properties) || <toolset-vacpp:version>12.1 in $(properties)
{
result += <library>/boost/chrono//boost_chrono ;
}

return $(result) ;
}

Expand All @@ -254,6 +254,11 @@ rule requirements ( properties * )
}
}
result += <define>BOOST_THREAD_DONT_USE_CHRONO ;

if <toolset>pgi in $(properties) || <toolset>vacpp in $(properties)
{
result += <library>/boost/atomic//boost_atomic ;
}

return $(result) ;
}
Expand Down
5 changes: 3 additions & 2 deletions example/future_then.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ int main()
BOOST_THREAD_LOG << "<MAIN" << BOOST_THREAD_END_LOG;
try
{
boost::future<int> f1 = boost::async(&p1);
boost::future<int> f1 = boost::async(boost::launch::async, &p1);
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
boost::future<int> f2 = f1.then(&p2);
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
BOOST_THREAD_LOG << f2.get() << BOOST_THREAD_END_LOG;
int i = f2.get();
BOOST_THREAD_LOG << i << BOOST_THREAD_END_LOG;
}
catch (std::exception& ex)
{
Expand Down
7 changes: 4 additions & 3 deletions example/once.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@

int value=0;
#ifdef BOOST_THREAD_PROVIDES_ONCE_CXX11
boost::once_flag once;
static boost::once_flag once;
//static boost::once_flag once2 = BOOST_ONCE_INIT;
#else
boost::once_flag once = BOOST_ONCE_INIT;
boost::once_flag once2 = once;
static boost::once_flag once = BOOST_ONCE_INIT;
//static boost::once_flag once2 = once;
#endif

void init()
Expand Down
72 changes: 72 additions & 0 deletions example/perf_shared_mutex.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// (C) Copyright 2013 Andrey
// (C) Copyright 2013 Vicente J. Botet Escriba
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// This performance test is based on the performance test provided by maxim.yegorushkin
// at https://svn.boost.org/trac/boost/ticket/7422

#define BOOST_THREAD_USES_CHRONO

#include <iostream>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/thread.hpp>
#include <boost/chrono/chrono_io.hpp>

#include <boost/thread/shared_mutex.hpp>

using namespace boost;

shared_mutex mtx;
const int cycles = 10000;

void shared()
{
int cycle(0);
while (++cycle < cycles)
{
shared_lock<shared_mutex> lock(mtx);
}
}

void unique()
{
int cycle(0);
while (++cycle < cycles)
{
unique_lock<shared_mutex> lock(mtx);
}
}

int main()
{
boost::chrono::high_resolution_clock::duration best_time(std::numeric_limits<boost::chrono::high_resolution_clock::duration::rep>::max());
for (int i =100; i>0; --i) {
boost::chrono::high_resolution_clock clock;
boost::chrono::high_resolution_clock::time_point s1 = clock.now();
thread t0(shared);
thread t1(shared);
thread t2(unique);
//thread t11(shared);
//thread t12(shared);
//thread t13(shared);

t0.join();
t1.join();
t2.join();
//t11.join();
// t12.join();
// t13.join();
boost::chrono::high_resolution_clock::time_point f1 = clock.now();
//std::cout << " Time spent:" << (f1 - s1) << std::endl;
best_time = std::min(best_time, f1 - s1);

}
std::cout << "Best Time spent:" << best_time << std::endl;
std::cout << "Time spent/cycle:" << best_time/cycles/3 << std::endl;

return 1;
}

27 changes: 26 additions & 1 deletion include/boost/thread/detail/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@
#define BOOST_THREAD_USES_CHRONO
#endif

#if ! defined BOOST_THREAD_DONT_USE_ATOMIC \
&& ! defined BOOST_THREAD_USES_ATOMIC
//#if ! defined __PGIC__
#define BOOST_THREAD_USES_ATOMIC
//#endif
//#define BOOST_THREAD_DONT_USE_ATOMIC
#endif

#if defined BOOST_THREAD_USES_ATOMIC
// Andrey Semashev
#define BOOST_THREAD_ONCE_ATOMIC
#else
//#elif ! defined BOOST_NO_CXX11_THREAD_LOCAL && ! defined BOOST_NO_THREAD_LOCAL && ! defined BOOST_THREAD_NO_UINT32_PSEUDO_ATOMIC
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2444.html#Appendix
#define BOOST_THREAD_ONCE_FAST_EPOCH
#endif
#if BOOST_THREAD_VERSION==2

// PROVIDE_PROMISE_LAZY
Expand All @@ -131,7 +147,7 @@
// fixme BOOST_THREAD_PROVIDES_ONCE_CXX11 doesn't works when thread.cpp is compiled BOOST_THREAD_VERSION 3
#if ! defined BOOST_THREAD_DONT_PROVIDE_ONCE_CXX11 \
&& ! defined BOOST_THREAD_PROVIDES_ONCE_CXX11
#define BOOST_THREAD_DONT_PROVIDE_ONCE_CXX11
#define BOOST_THREAD_PROVIDES_ONCE_CXX11
#endif

// THREAD_DESTRUCTOR_CALLS_TERMINATE_IF_JOINABLE
Expand Down Expand Up @@ -277,6 +293,15 @@
#define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN
#endif

// For C++11 call_once interface the compiler MUST support constexpr.
// Otherwise once_flag would be initialized during dynamic initialization stage, which is not thread-safe.
#if defined(BOOST_THREAD_PROVIDES_ONCE_CXX11)
#if defined(BOOST_NO_CXX11_CONSTEXPR)
#undef BOOST_THREAD_PROVIDES_ONCE_CXX11
#endif
#endif


// BOOST_THREAD_PROVIDES_DEPRECATED_FEATURES_SINCE_V3_0_0 defined by default up to Boost 1.52
// BOOST_THREAD_DONT_PROVIDE_DEPRECATED_FEATURES_SINCE_V3_0_0 defined by default up to Boost 1.55
#if defined BOOST_THREAD_PROVIDES_DEPRECATED_FEATURES_SINCE_V3_0_0
Expand Down
21 changes: 21 additions & 0 deletions include/boost/thread/detail/invoke.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

#include <boost/config.hpp>
#include <boost/static_assert.hpp>
#ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL
#include <functional>
#endif

namespace boost
{
Expand All @@ -31,6 +34,8 @@ namespace boost
! defined(BOOST_NO_CXX11_AUTO) && \
! defined(BOOST_NO_CXX11_RVALUE_REFERENCES)

#define BOOST_THREAD_PROVIDES_INVOKE

// // bullets 1 and 2

template <class Fp, class A0, class ...Args>
Expand Down Expand Up @@ -80,6 +85,22 @@ namespace boost
{
return boost::forward<Fp>(f)(boost::forward<Args>(args)...);
}
#else
#if ! defined(BOOST_NO_SFINAE_EXPR) && \
! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
! defined BOOST_NO_CXX11_HDR_FUNCTIONAL && \
! defined(BOOST_NO_CXX11_RVALUE_REFERENCES)

template <class Ret, class Fp, class ...Args>
inline
Ret invoke(Fp&& f, Args&& ...args)
{
return std::bind(boost::forward<Fp>(f), boost::forward<Args>(args)...)();
}

#define BOOST_THREAD_PROVIDES_INVOKE_RET

#endif

#endif
}
Expand Down
Loading

0 comments on commit f9b257e

Please sign in to comment.