1
2 // Copyright 2018 Peter Dimov.
3 //
4 // Distributed under the Boost Software License, Version 1.0.
5 //
6 // See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt
8
9 #include <boost/atomic.hpp>
10 #include <boost/core/lightweight_test.hpp>
11
12 struct X
13 {
14 int u_;
15 int v_;
16 int w_;
17
XX18 X(): u_( 0 ), v_( 0 ), w_( 0 )
19 {
20 }
21
XX22 X( int u, int v, int w ): u_( u ), v_( v ), w_( w )
23 {
24 }
25 };
26
main()27 int main()
28 {
29 boost::atomic<X> a;
30
31 a.store( X( 1, 2, 3 ) );
32 X x1 = a.exchange( X( 4, 5, 6 ) );
33
34 BOOST_TEST_EQ( x1.u_, 1 );
35 BOOST_TEST_EQ( x1.v_, 2 );
36 BOOST_TEST_EQ( x1.w_, 3 );
37
38 X x2 = a.load();
39
40 BOOST_TEST_EQ( x2.u_, 4 );
41 BOOST_TEST_EQ( x2.v_, 5 );
42 BOOST_TEST_EQ( x2.w_, 6 );
43
44 return boost::report_errors();
45 }
46