void test() { { boost::intrusive_ptr<X> px; test3(px, px); boost::intrusive_ptr<X> px2; test3(px, px2); boost::intrusive_ptr<X> px3(px); test3(px3, px3); test3(px, px3); } { boost::intrusive_ptr<X> px; boost::intrusive_ptr<X> px2(new X); test3(px, px2); test3(px2, px2); boost::intrusive_ptr<X> px3(new X); test3(px2, px3); boost::intrusive_ptr<X> px4(px2); test3(px2, px4); test3(px4, px4); } { boost::intrusive_ptr<X> px(new X); boost::intrusive_ptr<Y> py(new Y); test2(px, py); boost::intrusive_ptr<X> px2(py); test2(px2, py); test3(px, px2); test3(px2, px2); } }
int main() { boost::shared_ptr<X> px( new X ); { boost::shared_ptr<X> p2 = boost::atomic_load( &px ); BOOST_TEST_SP_EQ( p2, px ); boost::shared_ptr<X> px2( new X ); boost::atomic_store( &px, px2 ); BOOST_TEST_SP_EQ( px, px2 ); p2 = boost::atomic_load( &px ); BOOST_TEST_SP_EQ( p2, px ); BOOST_TEST_SP_EQ( p2, px2 ); boost::shared_ptr<X> px3( new X ); boost::shared_ptr<X> p3 = boost::atomic_exchange( &px, px3 ); BOOST_TEST_SP_EQ( p3, px2 ); BOOST_TEST_SP_EQ( px, px3 ); boost::shared_ptr<X> px4( new X ); boost::shared_ptr<X> cmp; bool r = boost::atomic_compare_exchange( &px, &cmp, px4 ); BOOST_TEST( !r ); BOOST_TEST_SP_EQ( px, px3 ); BOOST_TEST_SP_EQ( cmp, px3 ); r = boost::atomic_compare_exchange( &px, &cmp, px4 ); BOOST_TEST( r ); BOOST_TEST_SP_EQ( px, px4 ); } // px.reset(); { boost::shared_ptr<X> p2 = boost::atomic_load_explicit( &px, boost::memory_order_acquire ); BOOST_TEST_SP_EQ( p2, px ); boost::shared_ptr<X> px2( new X ); boost::atomic_store_explicit( &px, px2, boost::memory_order_release ); BOOST_TEST_SP_EQ( px, px2 ); boost::shared_ptr<X> p3 = boost::atomic_exchange_explicit( &px, boost::shared_ptr<X>(), boost::memory_order_acq_rel ); BOOST_TEST_SP_EQ( p3, px2 ); BOOST_TEST_SP_EQ( px, p2 ); boost::shared_ptr<X> px4( new X ); boost::shared_ptr<X> cmp( px2 ); bool r = boost::atomic_compare_exchange_explicit( &px, &cmp, px4, boost::memory_order_acquire, boost::memory_order_relaxed ); BOOST_TEST( !r ); BOOST_TEST_SP_EQ( px, p2 ); BOOST_TEST_SP_EQ( cmp, p2 ); r = boost::atomic_compare_exchange_explicit( &px, &cmp, px4, boost::memory_order_release, boost::memory_order_acquire ); BOOST_TEST( r ); BOOST_TEST_SP_EQ( px, px4 ); } return boost::report_errors(); }