1 #include <boost/config.hpp>
3 #if defined(BOOST_MSVC)
4 #pragma warning(disable: 4786) // identifier truncated in debug info
5 #pragma warning(disable: 4710) // function not inlined
6 #pragma warning(disable: 4711) // function selected for automatic inline expansion
7 #pragma warning(disable: 4514) // unreferenced inline removed
10 // shared_ptr_mt_test.cpp - tests shared_ptr with multiple threads
12 // Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
13 // Copyright (c) 2008 Peter Dimov
15 // Distributed under the Boost Software License, Version 1.0.
16 // See accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt
19 #include <boost/shared_ptr.hpp>
20 #include <boost/bind.hpp>
27 #include <boost/detail/lightweight_thread.hpp>
31 int const n = 1024 * 1024;
33 void test( boost::shared_ptr<int> const & pi )
35 std::vector< boost::shared_ptr<int> > v;
37 for( int i = 0; i < n; ++i )
43 int const m = 16; // threads
45 #if defined( BOOST_HAS_PTHREADS )
47 char const * thmodel = "POSIX";
51 char const * thmodel = "Windows";
57 using namespace std; // printf, clock_t, clock
59 printf( "Using %s threads: %d threads, %d iterations: ", thmodel, m, n );
61 boost::shared_ptr<int> pi( new int(42) );
67 for( int i = 0; i < m; ++i )
69 boost::detail::lw_thread_create( a[ i ], boost::bind( test, pi ) );
72 for( int j = 0; j < m; ++j )
74 pthread_join( a[j], 0 );
79 printf( "\n\n%.3f seconds.\n", static_cast<double>(t) / CLOCKS_PER_SEC );