|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r59686 - in sandbox/stm/branches/vbe/libs/stm: example example/tx test
From: vicente.botet_at_[hidden]
Date: 2010-02-14 19:17:26
Author: viboes
Date: 2010-02-14 19:17:24 EST (Sun, 14 Feb 2010)
New Revision: 59686
URL: http://svn.boost.org/trac/boost/changeset/59686
Log:
Boost.STM/vbe:
* renaming for language-like macros
* multiple inheritance works now
* cleanup
Added:
sandbox/stm/branches/vbe/libs/stm/example/dyn_poly.cpp (contents, props changed)
sandbox/stm/branches/vbe/libs/stm/example/multiple_inheritance.cpp (contents, props changed)
sandbox/stm/branches/vbe/libs/stm/example/tx/counter_ptr.cpp (contents, props changed)
Text files modified:
sandbox/stm/branches/vbe/libs/stm/example/bank.cpp | 34 ++++++++--------
sandbox/stm/branches/vbe/libs/stm/example/counter.cpp | 28 ++++++------
sandbox/stm/branches/vbe/libs/stm/example/counter_ptr.cpp | 28 ++++++------
sandbox/stm/branches/vbe/libs/stm/example/deep_singleton.cpp | 8 +-
sandbox/stm/branches/vbe/libs/stm/example/embed.cpp | 84 ++++++++++++++++++++--------------------
sandbox/stm/branches/vbe/libs/stm/example/non_tx_counter.cpp | 28 ++++++------
sandbox/stm/branches/vbe/libs/stm/example/singleton.cpp | 4
sandbox/stm/branches/vbe/libs/stm/example/tx/array.cpp | 8 +-
sandbox/stm/branches/vbe/libs/stm/example/tx/bank.cpp | 44 ++++++++++----------
sandbox/stm/branches/vbe/libs/stm/example/tx/list.cpp | 82 +++++++++++++++++++-------------------
sandbox/stm/branches/vbe/libs/stm/example/tx/list_sp.cpp | 72 +++++++++++++++++-----------------
sandbox/stm/branches/vbe/libs/stm/example/tx/numeric.cpp | 56 +++++++++++++-------------
sandbox/stm/branches/vbe/libs/stm/example/tx/pointer.cpp | 32 +++++++-------
sandbox/stm/branches/vbe/libs/stm/test/Jamfile.v2 | 7 +-
14 files changed, 259 insertions(+), 256 deletions(-)
Modified: sandbox/stm/branches/vbe/libs/stm/example/bank.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/example/bank.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/example/bank.cpp 2010-02-14 19:17:24 EST (Sun, 14 Feb 2010)
@@ -75,7 +75,7 @@
thread_initializer thi;
for(int i=10; i>0;--i)
{
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
int amount=random() % 1000;
#if 0
tx_ptr<bank> rd_bank(bank_);
@@ -87,7 +87,7 @@
int acc2=random() % rd_bank->accounts.size();
rd_bank->accounts[acc1]->Withdraw(amount);
rd_bank->accounts[acc2]->Deposit(amount+1);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
catch(...) {
cerr << "aborted"<< endl;
}
@@ -101,7 +101,7 @@
void create_db(bank* b, int nr_of_accounts){
- //BOOST_STM_ATOMIC(_) {
+ //BOOST_STM_TRANSACTION(_) {
{
for(int c=0;c<nr_of_accounts;++c){
tx_ptr<BankAccount> acc(make_tx_ptr<BankAccount>(c));
@@ -113,28 +113,28 @@
tx_ptr<BankAccount> a;
void account_withdraw_thr_basic() {
thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
a->Withdraw(10);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
void account_withdraw_thr() {
thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
make_wr_ptr(_,a)->Withdraw(10);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
void account_deposit_thr_basic() {
thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
a->Deposit(10);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
void account_deposit_thr() {
thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
make_wr_ptr(_,a)->Deposit(10);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
int test_account() {
@@ -157,17 +157,17 @@
void vector_int_assign_basic() {
thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
(*v)[0]+=10;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
void vector_int_assign() {
thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
wr_ptr<std::vector<int> > wrv(_,v);
(*wrv)[0]+=10;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
int test_vector_int() {
@@ -218,9 +218,9 @@
delete th1;
//th2->join();
//delete th2;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
mybank->print_balance();
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
#endif
#if 0
Modified: sandbox/stm/branches/vbe/libs/stm/example/counter.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/example/counter.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/example/counter.cpp 2010-02-14 19:17:24 EST (Sun, 14 Feb 2010)
@@ -27,45 +27,45 @@
void inc() {
thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
++counter;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
void decr() {
thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
--counter;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
bool check(int val) {
//thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
BOOST_STM_TX_RETURN(_, *counter==val);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
bool assign() {
//thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
counter=1;
counter2=counter;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
bool res;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
BOOST_STM_TX_RETURN(_, (*counter==1) && (*counter2==1) && (counter==counter2)) ;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return res;
}
bool test_const(stm::tx_obj<int> const& c) {
//thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
counter2=c;
- } BOOST_STM_END_ATOMIC
- BOOST_STM_ATOMIC(_) {
+ } BOOST_STM_RETRY
+ BOOST_STM_TRANSACTION(_) {
BOOST_STM_TX_RETURN(_, c==counter2) ;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
int test_counter() {
Modified: sandbox/stm/branches/vbe/libs/stm/example/counter_ptr.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/example/counter_ptr.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/example/counter_ptr.cpp 2010-02-14 19:17:24 EST (Sun, 14 Feb 2010)
@@ -32,65 +32,65 @@
void inc() {
thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
// ++(*counter_ptr)
read_ptr<tx_int_ptr> tx_counter_ptr_ptr(_, counter_ptr);
//tx_int_ptr tmp = *tx_counter_ptr_ptr;
write_ptr<tx_int> tx_counter_ptr(_, **tx_counter_ptr_ptr);
++(*tx_counter_ptr);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
void decr() {
thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
// --(*counter_ptr)
read_ptr<tx_int_ptr> tx_counter_ptr_ptr(_, counter_ptr);
write_ptr<tx_int> tx_counter_ptr(_, **tx_counter_ptr_ptr);
--(*tx_counter_ptr);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
bool check(int val) {
//thread_initializer thi;
bool res;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
// *counter_ptr==val
read_ptr<tx_int_ptr> tx_counter_ptr_ptr(_, counter_ptr);
read_ptr<tx_int> tx_counter_ptr(_, **tx_counter_ptr_ptr);
res =(*tx_counter_ptr==val);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return res;
}
bool assign() {
//thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
// *tx_counter2_ptr=*tx_counter_ptr;
read_ptr<tx_int_ptr> tx_counter_ptr_ptr(_, counter_ptr);
write_ptr<tx_int_ptr> tx_counter2_ptr_ptr(_, counter2_ptr);
tx_counter2_ptr_ptr=tx_counter_ptr_ptr;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
bool res=true;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
//res = (counter2_ptr==counter_ptr) ;
read_ptr<tx_int_ptr> tx_counter_ptr_ptr(_, counter_ptr);
read_ptr<tx_int_ptr> tx_counter2_ptr_ptr(_, counter2_ptr);
//res = (*tx_counter2_ptr_ptr==*tx_counter_ptr_ptr) ;
//res= (_.read(counter_ptr)==_.read(counter2_ptr));
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return res;
}
#if 0
bool test_const(tx_int_const_ptr& const ptr) {
//thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
write_ptr<tx_int_const_ptr> tx_counter_const_ptr_ptr(_, counter_const_ptr);
tx_counter_const_ptr_ptr=ptr;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
bool res=true;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
//res =(c==counter2) ;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return res;
}
#endif
Modified: sandbox/stm/branches/vbe/libs/stm/example/deep_singleton.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/example/deep_singleton.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/example/deep_singleton.cpp 2010-02-14 19:17:24 EST (Sun, 14 Feb 2010)
@@ -43,13 +43,13 @@
bool test() {
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
_.write_ptr(Singleton::instance());
Singleton::instance()->f=1;
- } BOOST_STM_END_ATOMIC
- BOOST_STM_ATOMIC(_) {
+ } BOOST_STM_RETRY
+ BOOST_STM_TRANSACTION(_) {
BOOST_STM_TX_RETURN(_, Singleton::instance()->f==1) ;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return false;
}
Added: sandbox/stm/branches/vbe/libs/stm/example/dyn_poly.cpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/libs/stm/example/dyn_poly.cpp 2010-02-14 19:17:24 EST (Sun, 14 Feb 2010)
@@ -0,0 +1,133 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// 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)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/stm.hpp>
+
+using namespace std;
+using namespace boost;
+using namespace boost::stm;
+
+
+class Base
+ : public transaction_object<Base>
+{
+public:
+ Base() : derived_called(false) {}
+ void mod_fct() {}
+ bool derived_called;
+};
+
+class Derived
+ : public Base
+{
+public:
+ static Derived* make_cache(Derived const& rhs, transaction& t) {
+ return new Derived(rhs);
+ };
+ virtual base_transaction_object* make_cache(transaction& t) const {
+ return make_cache(*this, t);
+ }
+ virtual void delete_cache() {
+ delete this;
+ }
+ virtual void copy_cache(base_transaction_object const &rhs)
+ {
+ *this = *static_cast<Derived const *>(&rhs);
+ }
+
+#if BUILD_MOVE_SEMANTICS
+ virtual void move_state(base_transaction_object * rhs)
+ {
+ *this = draco_move(*(static_cast<Derived*>(rhs)));
+ }
+#endif
+ Derived() : Base(), derived_mofified(false) {}
+ bool derived_mofified;
+ void mod_fct() {
+ derived_called=true;
+ }
+};
+
+class Derived2 : public transaction_object<Derived2, Base> {
+public:
+ Derived2() : transaction_object<Derived2, Base>(), derived_mofified(false) {}
+ bool derived_mofified;
+ void mod_fct() {
+ derived_called=true;
+ }
+};
+
+
+bool test1_KO() {
+ Base* ptrB = new Derived();
+ BOOST_STM_OUTER_TRANSACTION(_) {
+ _.write_ptr(ptrB)->mod_fct();
+ } BOOST_STM_RETRY
+ BOOST_STM_OUTER_TRANSACTION(_) {
+ BOOST_STM_TX_RETURN(_, dynamic_cast<Derived const*>(_.read_ptr(ptrB))->derived_mofified==false) ;
+ } BOOST_STM_RETRY
+ return false;
+}
+
+
+bool test2_KO() {
+ Base* ptrB = new Derived2();
+ BOOST_STM_OUTER_TRANSACTION(_) {
+ _.write_ptr(ptrB)->mod_fct();
+ } BOOST_STM_RETRY
+ BOOST_STM_OUTER_TRANSACTION(_) {
+ BOOST_STM_TX_RETURN(_, dynamic_cast<Derived2 const*>(_.read_ptr(ptrB))->derived_mofified==false) ;
+ //BOOST_STM_TX_RETURN(_, _.read_ptr(ptrB)->derived_called==false) ;
+ } BOOST_STM_RETRY
+ return false;
+}
+
+bool test1_OK() {
+ Base* ptrB = new Derived();
+ BOOST_STM_OUTER_TRANSACTION(_) {
+ _.write_ptr_dyn(ptrB)->mod_fct();
+ } BOOST_STM_RETRY
+ BOOST_STM_OUTER_TRANSACTION(_) {
+ BOOST_STM_TX_RETURN(_, dynamic_cast<Derived const*>(_.read_ptr(ptrB))->derived_mofified==true) ;
+ //BOOST_STM_TX_RETURN(_, _.read_ptr(ptrB)->derived_called==true) ;
+ } BOOST_STM_RETRY
+ return false;
+}
+
+
+bool test2_OK() {
+ Base* ptrB = new Derived2();
+ BOOST_STM_OUTER_TRANSACTION(_) {
+ _.write_ptr_dyn(ptrB)->mod_fct();
+ } BOOST_STM_RETRY
+ BOOST_STM_OUTER_TRANSACTION(_) {
+ BOOST_STM_TX_RETURN(_, dynamic_cast<Derived2 const*>(_.read_ptr(ptrB))->derived_mofified==true) ;
+ //BOOST_STM_TX_RETURN(_, _.read_ptr(ptrB)->derived_called==true) ;
+ } BOOST_STM_RETRY
+ return false;
+}
+
+int main() {
+ transaction::enable_dynamic_priority_assignment();
+ transaction::do_deferred_updating();
+ transaction::initialize();
+ thread_initializer thi;
+
+ int res=0;
+ res+=test1_OK();
+ //res+=test1_KO();
+ res+=test2_OK();
+ //res+=test2_KO();
+ return res;
+
+}
Modified: sandbox/stm/branches/vbe/libs/stm/example/embed.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/example/embed.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/example/embed.cpp 2010-02-14 19:17:24 EST (Sun, 14 Feb 2010)
@@ -11,7 +11,7 @@
//
//////////////////////////////////////////////////////////////////////////////
-
+
/*
Should we enable embedded TO?
@@ -38,17 +38,17 @@
write : address, size
pair<interval_map::iterator> r = get [address, address+size);
if (p.first!=p.second) // found
-
- if p.first.first==[address, address+size) //
+
+ if p.first.first==[address, address+size) //
return p.first.second.first
if p.first.first includes [address, address+size) //
return p.first.second.first + offset
create new cache
- for each interval
+ for each interval
update the cache with already written members
update smart pointers with new offset
- concatenate smart pointers list
-
+ concatenate smart pointers list
+
replace all the intervals by the new interval
else // not found
insert
@@ -56,7 +56,7 @@
This introduce an intrusive pointer class.
-All this sems quite complex and will decreased the performance of
+All this sems quite complex and will decreased the performance of
reads/writes and conflict detection.
*/
@@ -68,13 +68,13 @@
using namespace boost::stm;
-struct Inner : transaction_object<Inner>
+struct Inner : transaction_object<Inner>
{
Inner(): i(0) {}
int i;
};
-struct Outer : transaction_object<Outer>
+struct Outer : transaction_object<Outer>
{
Outer(): e(), j(0) {}
Inner e;
@@ -82,82 +82,82 @@
};
-
+
bool check_in_nested_fails() {
Outer obj;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
_.write(obj.e).i=1;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_INNER_TRANSACTION(_) {
std::cout <<__LINE__<<" "<< "obj.e.i 1!=" << _.read(obj).e.i << std::endl;
if (_.read(obj).e.i>0) {
std::cout <<__LINE__<<" "<< "obj.e.i 1!=" << _.read(obj).e.i << std::endl;
_.write(obj).j=2;
}
- } BOOST_STM_END_ATOMIC
- } BOOST_STM_END_ATOMIC
- BOOST_STM_ATOMIC(_) {
+ }
+ } BOOST_STM_RETRY
+ BOOST_STM_OUTER_TRANSACTION(_) {
std::cout <<__LINE__<<" "<< "obj.e.i 1=" << _.read(obj.e).i << std::endl;
std::cout <<__LINE__<<" "<< "obj.j 2!=" << _.read(obj).j << std::endl;
BOOST_STM_TX_RETURN(_, _.read(obj.e).i==1 && _.read(obj).j==2) ;
- } BOOST_STM_END_ATOMIC
- return false;
-}
+ } BOOST_STM_RETRY
+ return false;
+}
bool check_after_nested_fails() {
Outer obj;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
_.write(obj).j=0;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_INNER_TRANSACTION(_) {
_.write(obj.e).i=1;
- } BOOST_STM_END_ATOMIC
+ }
std::cout <<__LINE__<<" "<< "obj.e.i 1!=" << _.read(obj).e.i << std::endl;
if (_.read(obj).e.i>0)
_.write(obj).j=2;
- } BOOST_STM_END_ATOMIC
- BOOST_STM_ATOMIC(_) {
+ } BOOST_STM_RETRY
+ BOOST_STM_OUTER_TRANSACTION(_) {
std::cout <<__LINE__<<" "<< "obj.e.i 1=" << _.read(obj.e).i << std::endl;
std::cout <<__LINE__<<" "<< "obj.j 2!=" << _.read(obj).j << std::endl;
BOOST_STM_TX_RETURN(_, _.read(obj.e).i==1 && _.read(obj).j==2) ;
- } BOOST_STM_END_ATOMIC
- return false;
-}
+ } BOOST_STM_RETRY
+ return false;
+}
bool mod_outer_same_in_nested_fails() {
Outer obj;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
_.write(obj.e).i=1;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_INNER_TRANSACTION(_) {
_.write(obj).e.i=2;
- } BOOST_STM_END_ATOMIC
+ }
std::cout << "obj.e.i= 2!=" << _.read(obj.e).i << std::endl;
- } BOOST_STM_END_ATOMIC
- BOOST_STM_ATOMIC(_) {
+ } BOOST_STM_RETRY
+ BOOST_STM_OUTER_TRANSACTION(_) {
std::cout << "obj.e.i= 2!=" << _.read(obj.e).i << std::endl;
std::cout << "obj.j= 0=" << _.read(obj).j << std::endl;
BOOST_STM_TX_RETURN(_, _.read(obj.e).i==2 && _.read(obj).j==0) ;
- } BOOST_STM_END_ATOMIC
- return false;
-}
+ } BOOST_STM_RETRY
+ return false;
+}
bool mod_inner_same_in_nested_and_check_after_fails() {
Outer obj;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
_.write(obj).e.i=1;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_INNER_TRANSACTION(_) {
_.write(obj.e).i=2;
- } BOOST_STM_END_ATOMIC
+ }
std::cout << "obj.e.i= 2!=" << _.read(obj).e.i << std::endl;
if (_.read(obj).e.i>1)
_.write(obj).j=1;
//BOOST_STM_TX_RETURN(_, _.read(obj).e.i==2) ;
- } BOOST_STM_END_ATOMIC
- BOOST_STM_ATOMIC(_) {
+ } BOOST_STM_RETRY
+ BOOST_STM_OUTER_TRANSACTION(_) {
std::cout << "obj.e.i= 2=" << _.read(obj).e.i << std::endl;
std::cout << "obj.j= 1!=" << _.read(obj).j << std::endl;
BOOST_STM_TX_RETURN(_, _.read(obj).e.i==2 && _.read(obj).j==1) ;
- } BOOST_STM_END_ATOMIC
- return false;
-}
+ } BOOST_STM_RETRY
+ return false;
+}
int main() {
Added: sandbox/stm/branches/vbe/libs/stm/example/multiple_inheritance.cpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/libs/stm/example/multiple_inheritance.cpp 2010-02-14 19:17:24 EST (Sun, 14 Feb 2010)
@@ -0,0 +1,138 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// 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)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/stm.hpp>
+namespace boost { namespace stm {
+
+template <class B>
+struct virtually2 : virtual B {
+ // forward constructors
+};
+}}
+
+using namespace std;
+using namespace boost;
+using namespace boost::stm;
+
+struct B1 : transaction_object<B1,
+ virtually<base_transaction_object> >
+{
+ int i_;
+ B1() : i_(0), derived_called1(false) {}
+ B1(int i) : i_(i), derived_called1(false) {}
+ void mod_fct1() {}
+ bool derived_called1;
+};
+
+struct B2 : transaction_object<B2,
+ virtually<base_transaction_object> >
+{
+ int j_;
+ B2() : j_(0), derived_called2(false) {}
+ B2(int j) : j_(j), derived_called2(false) {}
+ void mod_fct2() {}
+ bool derived_called2;
+};
+
+#if 0
+struct D_aux : B1, B2
+ //virtually<base_transaction_object>
+{
+ // forward constructors
+ D_aux() : B1(1), B2(2) {}
+};
+
+#endif
+struct D : transaction_object2<D, B1, B2 >
+{
+ //D() : B1(1), B2(2) {}
+ void mod_fct1() {
+ derived_called1=true;
+ }
+ void mod_fct2() {
+ derived_called2=true;
+ }
+};
+
+
+#if 0
+#endif
+
+bool test1_KO() {
+ B1* ptrB1 = new D();
+ BOOST_STM_OUTER_TRANSACTION(_) {
+ _.write_ptr(ptrB1)->mod_fct1();
+ } BOOST_STM_RETRY
+ BOOST_STM_OUTER_TRANSACTION(_) {
+ BOOST_STM_TX_RETURN(_, _.read_ptr(ptrB1)->derived_called1==false) ;
+ } BOOST_STM_RETRY
+ return false;
+}
+
+
+bool test2_KO() {
+ B2* ptrB2 = new D();
+ BOOST_STM_OUTER_TRANSACTION(_) {
+ _.write_ptr(ptrB2)->mod_fct2();
+ } BOOST_STM_RETRY
+ BOOST_STM_OUTER_TRANSACTION(_) {
+ BOOST_STM_TX_RETURN(_, _.read_ptr(ptrB2)->derived_called2==false) ;
+ } BOOST_STM_RETRY
+ return false;
+}
+
+
+bool test1_OK() {
+ B1* ptrB1 = new D();
+ BOOST_STM_OUTER_TRANSACTION(_) {
+ _.write_ptr_dyn(ptrB1)->mod_fct1();
+ //~ B1* aptrB1=_.write_ptr_dyn(ptrB1);
+ //~ B1* optrB1 =_.find_original_ptr(aptrB1);
+ //~ B1* gptrB1 =_.get_written_ptr(aptrB1);
+ } BOOST_STM_RETRY
+ BOOST_STM_OUTER_TRANSACTION(_) {
+ BOOST_STM_TX_RETURN(_, _.read_ptr(ptrB1)->derived_called1==true) ;
+ } BOOST_STM_RETRY
+ return false;
+}
+
+
+bool test2_OK() {
+ B2* ptrB2 = new D();
+ BOOST_STM_OUTER_TRANSACTION(_) {
+ _.write_ptr_dyn(ptrB2)->mod_fct2();
+ } BOOST_STM_RETRY
+ BOOST_STM_OUTER_TRANSACTION(_) {
+ BOOST_STM_TX_RETURN(_, _.read_ptr(ptrB2)->derived_called2==true) ;
+ } BOOST_STM_RETRY
+ return false;
+}
+
+int main() {
+ transaction::enable_dynamic_priority_assignment();
+ transaction::do_deferred_updating();
+ transaction::initialize();
+ thread_initializer thi;
+
+//B1 b1;
+//typedef boost::is_virtual_base_of<boost::stm::base_transaction_object, B1> TT;
+//typedef boost::detail::safe_polymorphic_downcast<TT, B1, boost::stm::base_transaction_object> TT2;
+
+ int res=0;
+ res+=test1_OK();
+ //res+=test1_KO();
+ res+=test2_OK();
+ //res+=test2_KO();
+ return res;
+
+}
Modified: sandbox/stm/branches/vbe/libs/stm/example/non_tx_counter.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/example/non_tx_counter.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/example/non_tx_counter.cpp 2010-02-14 19:17:24 EST (Sun, 14 Feb 2010)
@@ -27,59 +27,59 @@
void inc() {
thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
non_tx::wr_ptr<int> tx_counter(_, counter);
++(*tx_counter);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
void decr() {
thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
non_tx::wr_ptr<int> tx_counter(_, counter);
--(*tx_counter);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
bool check(int val) {
//thread_initializer thi;
bool res;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
non_tx::rd_ptr<int> tx_counter(_, counter);
res =(*tx_counter==val);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return res;
}
bool assign() {
//thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
non_tx::wr_ptr<int> tx_counter(_, counter);
non_tx::wr_ptr<int> tx_counter2(_, counter2);
*tx_counter=1;
*tx_counter2=*tx_counter;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
bool res;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
non_tx::rd_ptr<int> tx_counter(_, counter);
non_tx::rd_ptr<int> tx_counter2(_, counter2);
res =(*tx_counter==1) && (*tx_counter2==1) && (tx_counter==tx_counter2) ;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return res;
}
bool test_const(int const& c) {
//thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
non_tx::rd_ptr<int> tx_c(_, c);
non_tx::wr_ptr<int> tx_counter2(_, counter2);
*tx_counter2=*tx_c;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
bool res;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
non_tx::rd_ptr<int> tx_c(_, c);
non_tx::wr_ptr<int> tx_counter2(_, counter2);
res =(*tx_c==*tx_counter2) ;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return res;
}
Modified: sandbox/stm/branches/vbe/libs/stm/example/singleton.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/example/singleton.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/example/singleton.cpp 2010-02-14 19:17:24 EST (Sun, 14 Feb 2010)
@@ -63,11 +63,11 @@
bool test() {
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
_.write_ptr(Singleton::instance());
Singleton::instance()->f=1;
} BOOST_STM_END_ATOMIC
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
BOOST_STM_TX_RETURN(_, Singleton::instance()->f==1) ;
} BOOST_STM_END_ATOMIC
return false;
Modified: sandbox/stm/branches/vbe/libs/stm/example/tx/array.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/example/tx/array.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/example/tx/array.cpp 2010-02-14 19:17:24 EST (Sun, 14 Feb 2010)
@@ -35,13 +35,13 @@
}
stm::tx::int_t v[2];
stm::tx::pointer<stm::tx::int_t > p;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
p = &v[0];
*p=1;
p = v;
++p;
*p=2;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return (v[0]==1) && (v[1]==2);
}
@@ -54,14 +54,14 @@
++p;
}
stm::tx::pointer<stm::tx::int_t > v;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
v= BOOST_STM_TX_NEW_ARRAY(_,2, stm::tx::int_t);
stm::tx::pointer<stm::tx::int_t > p;
p = &v[0];
p = v;
//++p;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
#if 0
{
Modified: sandbox/stm/branches/vbe/libs/stm/example/tx/bank.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/example/tx/bank.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/example/tx/bank.cpp 2010-02-14 19:17:24 EST (Sun, 14 Feb 2010)
@@ -36,20 +36,21 @@
}
void Deposit(int amount) {
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
balance_ += amount;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
int Withdraw(int amount) {
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
balance_ -= amount;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return amount;
}
int Balance() const {
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
BOOST_STM_TX_RETURN(_, balance_);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
+ return 0;
}
int Nb() const {
return nb_;
@@ -86,13 +87,13 @@
thread_initializer thi;
for(int i=10; i>0;--i)
{
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
int amount=random() % 1000;
int acc1=random() % bank_->accounts.size();
int acc2=random() % bank_->accounts.size();
bank_->accounts[acc1]->Withdraw(amount);
bank_->accounts[acc2]->Deposit(amount+1);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
catch(...) {
cerr << "aborted"<< endl;
}
@@ -107,33 +108,34 @@
void create_db(tx::pointer<Bank> b, int nr_of_accounts){
for(int c=0;c<nr_of_accounts;++c) {
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
tx::pointer<BankAccount> acc(BOOST_STM_TX_NEW_PTR(_, BankAccount(c)));
b->accounts.push_back(acc);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
}
tx::pointer<BankAccount> a;
+//tx::tx_ptr<BankAccount> a;
void account_withdraw_thr() {
thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
a->Withdraw(10);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
void account_deposit_thr() {
thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
a->Deposit(10);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
int test_account() {
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
a=BOOST_STM_TX_NEW_PTR(_, BankAccount(1));
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
thread th1(account_withdraw_thr);
thread th2(account_deposit_thr);
thread th3(account_withdraw_thr);
@@ -143,11 +145,11 @@
th2.join();
th3.join();
th4.join();
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
int res = (a->Balance()==0?0:1);
BOOST_STM_TX_DELETE_PTR(_, a.value());
BOOST_STM_TX_RETURN(_,res);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
bool test_bank() {
@@ -173,9 +175,9 @@
cin >> wait;Teller::exit=true;
th1.join();
th2.join();
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
address_of(mybank)->print_balance();
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
#endif
return true;
@@ -190,7 +192,7 @@
int res=0;
res+=test_account();
- res+=test_bank();
+ //res+=test_bank();
return res;
Added: sandbox/stm/branches/vbe/libs/stm/example/tx/counter_ptr.cpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/libs/stm/example/tx/counter_ptr.cpp 2010-02-14 19:17:24 EST (Sun, 14 Feb 2010)
@@ -0,0 +1,128 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// 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)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/stm.hpp>
+#include <boost/thread.hpp>
+#include <vector>
+#include <list>
+#include <stdlib.h>
+
+using namespace std;
+using namespace boost;
+using namespace boost::stm;
+
+typedef native_trans<int> tx_int;
+typedef transaction_object_ptr<tx_int> tx_int_ptr;
+typedef transaction_object_ptr<const tx_int> tx_int_const_ptr;
+
+tx_int counter;
+tx_int_ptr counter_ptr, counter2_ptr;
+//tx_int_const_ptr counter_const_ptr;
+
+void inc() {
+ thread_initializer thi;
+
+ BOOST_STM_OUTER_TRANSACTION(_) {
+ // ++(*counter_ptr)
+ read_ptr<tx_int_ptr> tx_counter_ptr_ptr(_, counter_ptr);
+ //tx_int_ptr tmp = *tx_counter_ptr_ptr;
+ write_ptr<tx_int> tx_counter_ptr(_, **tx_counter_ptr_ptr);
+ ++(*tx_counter_ptr);
+ } BOOST_STM_RETRY
+}
+void decr() {
+ thread_initializer thi;
+
+ BOOST_STM_OUTER_TRANSACTION(_) {
+ // --(*counter_ptr)
+ read_ptr<tx_int_ptr> tx_counter_ptr_ptr(_, counter_ptr);
+ write_ptr<tx_int> tx_counter_ptr(_, **tx_counter_ptr_ptr);
+ --(*tx_counter_ptr);
+ } BOOST_STM_RETRY
+}
+bool check(int val) {
+ //thread_initializer thi;
+ bool res;
+ BOOST_STM_OUTER_TRANSACTION(_) {
+ // *counter_ptr==val
+ read_ptr<tx_int_ptr> tx_counter_ptr_ptr(_, counter_ptr);
+ read_ptr<tx_int> tx_counter_ptr(_, **tx_counter_ptr_ptr);
+ res =(*tx_counter_ptr==val);
+ } BOOST_STM_RETRY
+ return res;
+}
+
+bool assign() {
+ //thread_initializer thi;
+ BOOST_STM_OUTER_TRANSACTION(_) {
+ // *tx_counter2_ptr=*tx_counter_ptr;
+ read_ptr<tx_int_ptr> tx_counter_ptr_ptr(_, counter_ptr);
+ write_ptr<tx_int_ptr> tx_counter2_ptr_ptr(_, counter2_ptr);
+ tx_counter2_ptr_ptr=tx_counter_ptr_ptr;
+ } BOOST_STM_RETRY
+ bool res=true;
+ BOOST_STM_OUTER_TRANSACTION(_) {
+ //res = (counter2_ptr==counter_ptr) ;
+ read_ptr<tx_int_ptr> tx_counter_ptr_ptr(_, counter_ptr);
+ read_ptr<tx_int_ptr> tx_counter2_ptr_ptr(_, counter2_ptr);
+ //res = (*tx_counter2_ptr_ptr==*tx_counter_ptr_ptr) ;
+ //res= (_.read(counter_ptr)==_.read(counter2_ptr));
+ } BOOST_STM_RETRY
+ return res;
+}
+#if 0
+bool test_const(tx_int_const_ptr& const ptr) {
+ //thread_initializer thi;
+ BOOST_STM_OUTER_TRANSACTION(_) {
+ write_ptr<tx_int_const_ptr> tx_counter_const_ptr_ptr(_, counter_const_ptr);
+ tx_counter_const_ptr_ptr=ptr;
+ } BOOST_STM_RETRY
+ bool res=true;
+ BOOST_STM_OUTER_TRANSACTION(_) {
+ //res =(c==counter2) ;
+ } BOOST_STM_RETRY
+ return res;
+}
+#endif
+
+int test_counter() {
+ atomic(_) {
+ write_ptr<tx_int_ptr> tx_counter_ptr_ptr(_, counter_ptr);
+ *tx_counter_ptr_ptr=BOOST_STM_TX_NEW_PTR(_, tx_int());
+ } end_atom
+ thread th1(inc);
+ thread th2(decr);
+ thread th3(inc);
+ thread th4(inc);
+
+ th1.join();
+ th2.join();
+ th3.join();
+ th4.join();
+
+ int fails=0;
+ fails += check(2);
+ fails += !assign();
+ //fails += !test_const(counter);
+ return fails;
+}
+
+int main() {
+ transaction::enable_dynamic_priority_assignment();
+ transaction::do_deferred_updating();
+ transaction::initialize();
+ thread_initializer thi;
+ srand(time(0));
+
+ return test_counter();
+}
Modified: sandbox/stm/branches/vbe/libs/stm/example/tx/list.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/example/tx/list.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/example/tx/list.cpp 2010-02-14 19:17:24 EST (Sun, 14 Feb 2010)
@@ -27,15 +27,15 @@
{
public:
- list_node() : value_(), next_()
+ list_node() : value_(), next_()
, binds_()
{
bind(&value_);
bind(&next_);
}
- explicit list_node(T const &rhs)
+ explicit list_node(T const &rhs)
: value_(rhs), next_() {}
- list_node(T const &rhs, list_node<T>* next)
+ list_node(T const &rhs, list_node<T>* next)
: value_(rhs), next_(next) {}
// zero initialization for native types
@@ -69,7 +69,7 @@
void bind(base_transaction_object* bto) {binds_.push_back(bto);}
-public:
+public:
list()
: head_(BOOST_STM_NEW_PTR(list_node<T>()))
, size_(0)
@@ -82,9 +82,9 @@
~list() { }
std::size_t size() const {
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
BOOST_STM_TX_RETURN(_, size_);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return 0;
}
@@ -92,7 +92,7 @@
// find the location to insert the node. if the value already exists, fail
//--------------------------------------------------------------------------
void insert(const T& val) {
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
list_node<T> * prev = head_;
list_node<T> * curr = prev->next_;
while (curr!=0) {
@@ -105,7 +105,7 @@
prev->next_=BOOST_STM_TX_NEW_PTR(_,list_node<T>(val, curr));
++size_;
}
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
catch (...) {
cerr << __LINE__ << " * insert" << endl;
}
@@ -113,21 +113,21 @@
// search function
bool lookup(const T& val) const {
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
list_node<T> const * curr=head_->next_;
while (curr) {
if (curr->value_ >= val) break;
curr = curr->next_;
}
BOOST_STM_RETURN((curr) && (curr->value_ == val));
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return false;
}
// remove a node if its value == val
void remove(const T& val)
{
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
// find the node whose val matches the request
list_node<T> * prev=head_;
list_node<T> * curr=prev->next_;
@@ -146,7 +146,7 @@
prev = curr;
curr = prev->next_;
}
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
};
@@ -157,94 +157,94 @@
test::list_node<int> n;
void create() {
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
cerr << __LINE__ << " create" << endl;
cerr << " create size " << l.size() << endl;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
catch (...) {
cerr << "aborted" << endl;
}
}
bool check_size(std::size_t val) {
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
BOOST_STM_RETURN(l.size()==val);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return false;
}
bool check_lookup(int val) {
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
//cerr << " check_lookup " << l.lookup(val) << endl;
BOOST_STM_RETURN(l.lookup(val));
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return false;
}
bool insert1() {
//thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
int val = 10;
l.insert(val);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return check_size(1);
}
void insert1_th() {
thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
l.insert(1);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
void insert2_th() {
thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
l.insert(2);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
void remove2() {
//thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
l.remove(2);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
void insert3_th() {
thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
l.insert(3);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
bool n1() {
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
int val = 10;
n.next_=BOOST_STM_TX_NEW_PTR(_,test::list_node<int>(val, 0));
- } BOOST_STM_END_ATOMIC
- BOOST_STM_ATOMIC(_) {
+ } BOOST_STM_RETRY
+ BOOST_STM_TRANSACTION(_) {
BOOST_STM_RETURN(n.next_->value_==10);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return false;
}
bool n2() {
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
n.next_->value_=12;
- } BOOST_STM_END_ATOMIC
- BOOST_STM_ATOMIC(_) {
+ } BOOST_STM_RETRY
+ BOOST_STM_TRANSACTION(_) {
BOOST_STM_RETURN(n.next_->value_==12);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return false;
}
bool n3() {
//cerr << __LINE__ << " * n3" << endl;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
test::list_node<int>* prev =&n;
test::list_node<int>* curr =prev->next_;
int val = 10;
prev->next_=BOOST_STM_TX_NEW_PTR(_,test::list_node<int>(val, curr));
- } BOOST_STM_END_ATOMIC
- BOOST_STM_ATOMIC(_) {
+ } BOOST_STM_RETRY
+ BOOST_STM_TRANSACTION(_) {
BOOST_STM_RETURN(n.next_->value_==10);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return false;
}
@@ -260,7 +260,7 @@
thread th2(insert2_th);
thread th3(insert2_th);
thread th4(insert3_th);
-
+
th1.join();
th2.join();
th3.join();
Modified: sandbox/stm/branches/vbe/libs/stm/example/tx/list_sp.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/example/tx/list_sp.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/example/tx/list_sp.cpp 2010-02-14 19:17:24 EST (Sun, 14 Feb 2010)
@@ -66,9 +66,9 @@
~list() {}
std::size_t size() const {
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
BOOST_STM_TX_RETURN(_, size_);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return 0;
}
@@ -76,7 +76,7 @@
// find the location to insert the node. if the value already exists, fail
//--------------------------------------------------------------------------
void insert(const T& val) {
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
read_ptr<list_node<T> > prev(_, head_);
read_ptr<list_node<T> > curr(_, prev->next_);
while (curr!=0) {
@@ -89,7 +89,7 @@
make_write_ptr<static_poly>(prev)->next_=BOOST_STM_TX_NEW_PTR(_,list_node<T>(val, curr.get()));
++(make_write_ptr<static_poly>(_, this)->size_);
}
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
catch (...) {
cout << __LINE__ << " * insert" << endl;
}
@@ -97,21 +97,21 @@
// search function
bool lookup(const T& val) const {
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
read_ptr<list_node<T> > curr(_, head_->next_);
while (curr) {
if (curr->value_ >= val) break;
curr = curr->next_;
}
BOOST_STM_RETURN((curr) && (curr->value_ == val));
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return false;
}
// remove a node if its value == val
void remove(const T& val)
{
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
// find the node whose val matches the request
read_ptr<list_node<T> > prev(_, head_);
read_ptr<list_node<T> > curr(_, prev->next_);
@@ -133,7 +133,7 @@
prev = curr;
curr = prev->next_;
}
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
};
@@ -144,93 +144,93 @@
test::list_node<int> n;
void create() {
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
cout << __LINE__ << " create" << endl;
cout << " create size " << l.size() << endl;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
catch (...) {
cout << "aborted" << endl;
}
}
bool check_size(std::size_t val) {
- //BOOST_STM_ATOMIC(_) {
+ //BOOST_STM_TRANSACTION(_) {
BOOST_STM_RETURN(l.size()==val);
- //} BOOST_STM_END_ATOMIC
+ //} BOOST_STM_RETRY
return false;
}
bool check_lookup(int val) {
- //BOOST_STM_ATOMIC(_) {
+ //BOOST_STM_TRANSACTION(_) {
BOOST_STM_RETURN(l.lookup(val));
- //} BOOST_STM_END_ATOMIC
+ //} BOOST_STM_RETRY
return false;
}
bool insert1() {
//thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
int val = 10;
l.insert(val);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return check_size(1);
}
void insert1_th() {
thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
l.insert(1);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
void insert2_th() {
thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
l.insert(2);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
void remove2() {
//thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
l.remove(2);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
void insert3_th() {
thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
l.insert(3);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
bool n1() {
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
int val = 10;
n.next_=BOOST_STM_TX_NEW_PTR(_,test::list_node<int>(val, 0));
- } BOOST_STM_END_ATOMIC
- BOOST_STM_ATOMIC(_) {
+ } BOOST_STM_RETRY
+ BOOST_STM_TRANSACTION(_) {
BOOST_STM_RETURN(n.next_->value_==10);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return false;
}
bool n2() {
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
n.next_->value_=12;
- } BOOST_STM_END_ATOMIC
- BOOST_STM_ATOMIC(_) {
+ } BOOST_STM_RETRY
+ BOOST_STM_TRANSACTION(_) {
BOOST_STM_RETURN(n.next_->value_==12);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return false;
}
bool n3() {
//cout << __LINE__ << " * n3" << endl;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
test::list_node<int>* prev =&n;
test::list_node<int>* curr =prev->next_;
int val = 10;
prev->next_=BOOST_STM_TX_NEW_PTR(_,test::list_node<int>(val, curr));
- } BOOST_STM_END_ATOMIC
- BOOST_STM_ATOMIC(_) {
+ } BOOST_STM_RETRY
+ BOOST_STM_TRANSACTION(_) {
BOOST_STM_RETURN(n.next_->value_==10);
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return false;
}
Modified: sandbox/stm/branches/vbe/libs/stm/example/tx/numeric.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/example/tx/numeric.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/example/tx/numeric.cpp 2010-02-14 19:17:24 EST (Sun, 14 Feb 2010)
@@ -28,104 +28,104 @@
void inc() {
stm::thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
++counter;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
void inc1() {
stm::thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
counter+=1;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
void decr() {
stm::thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
--counter;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
}
bool check(int val) {
//thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
BOOST_STM_TX_RETURN(_, (counter==val));
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return false;
}
bool test_equal() {
//thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
counter=1;
counter2=2;
BOOST_STM_TX_GOTO(_, label1);
counter2=3;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
label1:
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
counter=2;
//assert(counter==counter2);
BOOST_STM_TX_RETURN(_, (counter==counter2));
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return false;
}
bool test_assign() {
//thread_initializer thi;
for(int i=0; i<2;++i)
- BOOST_STM_ATOMIC_IN_LOOP(_) {
+ BOOST_STM_TRANSACTION_IN_LOOP(_) {
counter=1;
counter2=counter;
BOOST_STM_CONTINUE(_);
counter2=3;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
//assert((counter==1) && (counter2==1) && (counter==counter2));
BOOST_STM_TX_RETURN(_, (counter==1) && (counter2==1) && (counter==counter2)) ;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return false;
}
bool test_less() {
//thread_initializer thi;
for(;;)
- BOOST_STM_ATOMIC_IN_LOOP(_) {
+ BOOST_STM_TRANSACTION_IN_LOOP(_) {
counter=1;
counter2=2;
BOOST_STM_BREAK(_);
counter2=0;
- } BOOST_STM_END_ATOMIC
- BOOST_STM_ATOMIC(_) {
+ } BOOST_STM_RETRY
+ BOOST_STM_TRANSACTION(_) {
//assert(counter<counter2);
BOOST_STM_TX_RETURN(_, (counter<counter2)) ;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return false;
}
bool test_le() {
//thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
counter=1;
counter2=1;
- } BOOST_STM_END_ATOMIC
- BOOST_STM_ATOMIC(_) {
+ } BOOST_STM_RETRY
+ BOOST_STM_TRANSACTION(_) {
//assert(counter<=counter2);
BOOST_STM_TX_RETURN(_, (counter<=counter2)) ;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return false;
}
bool test_const(stm::tx::numeric<int> const& c) {
//thread_initializer thi;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TRANSACTION(_) {
counter2=c;
- } BOOST_STM_END_ATOMIC
- BOOST_STM_ATOMIC(_) {
+ } BOOST_STM_RETRY
+ BOOST_STM_TRANSACTION(_) {
//assert(c==counter2);
BOOST_STM_TX_RETURN(_, (c==counter2)) ;
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return false;
}
Modified: sandbox/stm/branches/vbe/libs/stm/example/tx/pointer.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/example/tx/pointer.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/example/tx/pointer.cpp 2010-02-14 19:17:24 EST (Sun, 14 Feb 2010)
@@ -67,12 +67,12 @@
stm::tx::pointer<const int> const cpc = pc;
//cpc=pc2; // this must not compile
stm::tx::pointer<stm::tx::pointer<const int> > ppc;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
pc=&cj;
- } end_atom
- BOOST_STM_ATOMIC(_) {
+ } BOOST_STM_RETRY
+ BOOST_STM_OUTER_TRANSACTION(_) {
BOOST_STM_TX_RETURN(_, (pc==&cj)&&(*pc==20)&&(*cpc==10));
- } end_atom
+ } BOOST_STM_RETRY
return false;
}
@@ -84,12 +84,12 @@
stm::tx::pointer<const int> const cpc = pc;
//cpc=pc2; // this must not compile
stm::tx::pointer<stm::tx::pointer<const int> > ppc;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
pc=pc2;
- } BOOST_STM_END_ATOMIC
- BOOST_STM_ATOMIC(_) {
+ } BOOST_STM_RETRY
+ BOOST_STM_OUTER_TRANSACTION(_) {
BOOST_STM_TX_RETURN(_, (pc==&cj)&&(*pc==20)&&(*cpc==10));
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return false;
}
@@ -98,26 +98,26 @@
stm::tx::int_t i;
stm::tx::pointer<stm::tx::int_t > p;
stm::tx::pointer<stm::tx::int_t > const cp = &i;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
i=5;
p=&i;
- } BOOST_STM_END_ATOMIC
- BOOST_STM_ATOMIC(_) {
+ } BOOST_STM_RETRY
+ BOOST_STM_OUTER_TRANSACTION(_) {
BOOST_STM_TX_RETURN(_, (i==5)&&(p==&i));
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return false;
}
bool test_ptr_to_tx_assignment() {
A a;
B b;
- BOOST_STM_ATOMIC(_) {
+ BOOST_STM_OUTER_TRANSACTION(_) {
b.a_ptr=&a;
b.a_ptr->i =1;
- } BOOST_STM_END_ATOMIC
- BOOST_STM_ATOMIC(_) {
+ } BOOST_STM_RETRY
+ BOOST_STM_OUTER_TRANSACTION(_) {
BOOST_STM_TX_RETURN(_, (b.a_ptr->i==1)&&(*b.a_ptr->ptr==1));
- } BOOST_STM_END_ATOMIC
+ } BOOST_STM_RETRY
return false;
}
Modified: sandbox/stm/branches/vbe/libs/stm/test/Jamfile.v2
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/test/Jamfile.v2 (original)
+++ sandbox/stm/branches/vbe/libs/stm/test/Jamfile.v2 2010-02-14 19:17:24 EST (Sun, 14 Feb 2010)
@@ -188,7 +188,8 @@
alias embedded
:
- [ run ../example/embed.cpp ]
+ [ run-fail ../example/embed.cpp ]
+ [ run ../example/multiple_inheritance.cpp ]
;
alias examples_tx
@@ -197,12 +198,12 @@
[ run ../example/singleton.cpp ]
[ run ../example/dyn_poly.cpp ]
- [ run ../example/tx/bank.cpp : : : : tx_bank ]
+ #[ run ../example/tx/bank.cpp : : : : tx_bank ]
[ run ../example/tx/numeric.cpp ]
[ run ../example/tx/array.cpp ]
[ run ../example/tx/pointer.cpp ]
[ run ../example/tx/list.cpp : : : : tx_list ]
- [ run ../example/tx/list_sp.cpp : : : : tx_list_sp ]
+ #[ run ../example/tx/list_sp.cpp : : : : tx_list_sp ]
;
#alias examples_txw
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk