Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57467 - in sandbox/stm/branches/vbe: boost/stm libs/stm/example libs/stm/example/tx libs/stm/test
From: vicente.botet_at_[hidden]
Date: 2009-11-07 16:28:21


Author: viboes
Date: 2009-11-07 16:28:19 EST (Sat, 07 Nov 2009)
New Revision: 57467
URL: http://svn.boost.org/trac/boost/changeset/57467

Log:
TBoost.STM vbe:
* Add as_new, as_new_array, delete_ptr and delete_array using enable_if
* Make use of BOOST_STM_NEW_PTR macros

Added:
   sandbox/stm/branches/vbe/libs/stm/example/tx/array.cpp (contents, props changed)
   sandbox/stm/branches/vbe/libs/stm/example/tx/numeric.cpp (contents, props changed)
Removed:
   sandbox/stm/branches/vbe/libs/stm/example/numeric.cpp
Text files modified:
   sandbox/stm/branches/vbe/boost/stm/language_like.hpp | 6
   sandbox/stm/branches/vbe/boost/stm/transaction.hpp | 257 ++++++++++++++++++++++++++++++++-------
   sandbox/stm/branches/vbe/libs/stm/example/bank.cpp | 36 ++--
   sandbox/stm/branches/vbe/libs/stm/example/counter.cpp | 28 ++--
   sandbox/stm/branches/vbe/libs/stm/example/counter_ptr.cpp | 30 ++--
   sandbox/stm/branches/vbe/libs/stm/example/list.cpp | 8
   sandbox/stm/branches/vbe/libs/stm/example/non_tx_counter.cpp | 28 ++--
   sandbox/stm/branches/vbe/libs/stm/example/tx/pointer.cpp | 111 ++--------------
   sandbox/stm/branches/vbe/libs/stm/test/Jamfile.v2 | 5
   9 files changed, 299 insertions(+), 210 deletions(-)

Modified: sandbox/stm/branches/vbe/boost/stm/language_like.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/language_like.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/language_like.hpp 2009-11-07 16:28:19 EST (Sat, 07 Nov 2009)
@@ -95,7 +95,7 @@
 // Catch a unnamed abort exception and retry
 //---------------------------------------------------------------------------
 #define BOOST_STM_RETRY catch (boost::stm::aborted_tx &) {}
-#define BOOST_STM_END_ATOM BOOST_STM_RETRY
+#define BOOST_STM_END_ATOMIC BOOST_STM_RETRY
 
 //---------------------------------------------------------------------------
 // Catch a named exception and re-throw it after commiting
@@ -265,14 +265,14 @@
 //---------------------------------------------------------------------------
 
 #define BOOST_STM_TX_DELETE_PTR(TX, PTR) \
- (TX).delete_tx_ptr(PTR);
+ (TX).delete_ptr(PTR)
 
 //---------------------------------------------------------------------------
 // deletes the allocated object on transaction TX
 //---------------------------------------------------------------------------
 
 #define BOOST_STM_TX_DELETE_ARRAY(TX, PTR) \
- (TX).delete_tx_array(PTR);
+ (TX).delete_array(PTR)
 
 //---------------------------------------------------------------------------
 // deletes the allocated object on transaction TX

Modified: sandbox/stm/branches/vbe/boost/stm/transaction.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/transaction.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/transaction.hpp 2009-11-07 16:28:19 EST (Sat, 07 Nov 2009)
@@ -30,6 +30,11 @@
 //-----------------------------------------------------------------------------
 #include <boost/stm/detail/config.hpp>
 //-----------------------------------------------------------------------------
+#ifdef BOOST_STM_USE_BOOST
+#include <boost/utility/enable_if.hpp>
+#include <boost/type_traits/is_base_of.hpp>
+#endif
+//-----------------------------------------------------------------------------
 #include <boost/stm/base_transaction.hpp>
 #include <boost/stm/datatypes.hpp>
 #include <boost/stm/transaction_bookkeeping.hpp>
@@ -555,28 +560,84 @@
       }
    }
 
+ //--------------------------------------------------------------------------
    template <typename T>
    inline void delete_tx_ptr(T *in) {
        delete_memory(*in);
    }
 
+ //--------------------------------------------------------------------------
+ template <typename T>
+ inline void delete_non_tx_ptr(T *in) {
+ delete_memory(*in);
+ }
+ #ifdef BOOST_STM_USE_BOOST
+ template <int> struct dummy { dummy(int) {} };
+//--------------------------------------------------------------------------
+ template <typename T>
+ inline
+ typename boost::enable_if<is_base_of<base_transaction_object, T>, void>::type
+ delete_ptr(T *in, dummy<0> = 0) {
+ delete_tx_ptr(in);
+ }
+ template <typename T>
+ inline
+ typename boost::disable_if<is_base_of<base_transaction_object, T>, void>::type
+ delete_ptr(T *in, dummy<1> = 0) {
+ delete_non_tx_ptr(in);
+ }
+ #endif
+
+ //--------------------------------------------------------------------------
+ template <typename T>
+ inline void delete_tx_array(T *in, std::size_t size) {
+ if (direct_updating())
+ {
+#if PERFORMING_VALIDATION
+ throw "direct updating not implemented for validation yet";
+#else
+ direct_delete_tx_array(in, size);
+#endif
+ }
+ else
+ {
+ deferred_delete_tx_array(in, size);
+ }
+ }
+ //--------------------------------------------------------------------------
    template <typename T>
- inline void delete_tx_array(T *in) {
+ inline void delete_non_tx_array(T *in, std::size_t size) {
       if (direct_updating())
       {
 #if PERFORMING_VALIDATION
          throw "direct updating not implemented for validation yet";
 #else
- direct_delete_tx_array(in);
+ direct_delete_tx_array(in, size);
 #endif
       }
       else
       {
- deferred_delete_tx_array(in);
+ deferred_delete_tx_array(in, size);
       }
    }
 
    //--------------------------------------------------------------------------
+ #ifdef BOOST_STM_USE_BOOST
+ template <typename T>
+ inline
+ typename boost::enable_if<is_base_of<base_transaction_object, T>, void>::type
+ delete_array(T *in, std::size_t size, dummy<0> = 0) {
+ delete_tx_ptr(in, size);
+ }
+ template <typename T>
+ inline
+ typename boost::disable_if<is_base_of<base_transaction_object, T>, void>::type
+ delete_array(T *in, std::size_t size, dummy<1> = 0) {
+ delete_non_tx_ptr(in, size);
+ }
+ #endif
+
+ //--------------------------------------------------------------------------
    // allocation of new memory behaves the same for both deferred and direct
    // transaction implementations
    //--------------------------------------------------------------------------
@@ -596,7 +657,7 @@
 
    //--------------------------------------------------------------------------
    template <typename T>
- T* as_new(T *newNode)
+ T* as_new_tx(T *newNode)
    {
       newNode->transaction_thread(threadId_);
       newNode->new_memory(1);
@@ -605,17 +666,54 @@
       return newNode;
    }
 
+ #ifdef BOOST_STM_USE_BOOST
    //--------------------------------------------------------------------------
    template <typename T>
- T* as_new_array(T *newNode, std::size_t size)
+ inline
+ typename enable_if<is_base_of<base_transaction_object, T>, T*>::type
+ as_new(T *in, dummy<0> = 0) {
+ return as_new_tx(in);
+ }
+ template <typename T>
+ inline
+ typename disable_if<is_base_of<base_transaction_object, T>, T*>::type
+ as_new(T *in, dummy<1> = 0) {
+ return as_new_non_tx(in);
+ }
+ #endif
+ //--------------------------------------------------------------------------
+ template <typename T>
+ T* as_new_tx_array(T *newNode, std::size_t size)
+ {
+ newMemoryList().push_back(detail::make_array(newNode, size));
+
+ return newNode;
+ }
+
+ //--------------------------------------------------------------------------
+ template <typename T>
+ T* as_new_non_tx_array(T *newNode, std::size_t size)
    {
- //newNode->transaction_thread(threadId_);
- //newNode->new_memory(1);
       newMemoryList().push_back(detail::make_array(newNode, size));
 
       return newNode;
    }
 
+ #ifdef BOOST_STM_USE_BOOST
+ //--------------------------------------------------------------------------
+ template <typename T>
+ inline
+ typename enable_if<is_base_of<base_transaction_object, T>, T*>::type
+ as_new_array(T *in, std::size_t size, dummy<0> = 0) {
+ return as_new_tx_array(in, size);
+ }
+ template <typename T>
+ inline
+ typename disable_if<is_base_of<base_transaction_object, T>, T*>::type
+ as_new_array(T *in, std::size_t size, dummy<1> = 0) {
+ return as_new_non_tx_array(in, size);
+ }
+ #endif
    //--------------------------------------------------------------------------
    template <typename T>
    T* new_shared_memory(T*)
@@ -905,35 +1003,49 @@
 
    //--------------------------------------------------------------------------
    template <typename T>
- void direct_delete_tx_array(T *in)
+ void direct_delete_tx_array(T *in, std::size_t size)
    {
- if (in.transaction_thread() == threadId_)
- {
- deletedMemoryList().push_back(detail::make(in));
- return;
- }
-
- //-----------------------------------------------------------------------
- // if we're here this item isn't in our writeList - get the global lock
- // and see if anyone else is writing to it. if not, we add the item to
- // our write list and our deletedList
- //-----------------------------------------------------------------------
- synchro::unique_lock<Mutex> lock_m(transactionMutex_);
+ bool all_in_this_thread = true;
+ for (int i=size-1; i>=0; --i) {
+ if (in[i].transaction_thread() != threadId_) {
+ all_in_this_thread=false;
+ break;
+ }
+ }
+ if (all_in_this_thread) {
+ deletedMemoryList().push_back(detail::make_array(in, size));
+ return;
+ }
 
- if (in.transaction_thread() != invalid_thread_id())
- {
- cm_abort_on_write(*this, (base_transaction_object&)(in));
- }
- else
- {
- in.transaction_thread(threadId_);
- lock_m.unlock();
- // is this really necessary? in the deferred case it is, but in direct it
- // doesn't actually save any time for anything
- //writeList()[(base_transaction_object*)&in] = 0;
+ //-----------------------------------------------------------------------
+ // if we're here this item isn't in our writeList - get the global lock
+ // and see if anyone else is writing to it. if not, we add the item to
+ // our write list and our deletedList
+ //-----------------------------------------------------------------------
+ synchro::unique_lock<Mutex> lock_m(transactionMutex_);
+
+ bool all_invalid = true;
+ for (int i=size-1; i>=0; --i) {
+ if (in[i].transaction_thread() = invalid_thread_id()) {
+ all_invalid=false;
+ break;
+ }
+ }
+ if (!all_invalid) {
+ cm_abort_on_write(*this, (base_transaction_object&)(*in));
+ }
+ else
+ {
+ for (int i=size-1; i>=0; --i) {
+ in[i].transaction_thread(threadId_);
+ }
+ lock_m.unlock();
+ // is this really necessary? in the deferred case it is, but in direct it
+ // doesn't actually save any time for anything
+ //writeList()[(base_transaction_object*)&in] = 0;
 
- deletedMemoryList().push_back(detail::make(in));
- }
+ deletedMemoryList().push_back(detail::make_array(in, size));
+ }
    }
 #endif
 
@@ -1064,10 +1176,9 @@
       //-----------------------------------------------------------------------
       if (in.transaction_thread() != invalid_thread_id())
       {
- { synchro::lock_guard<Mutex> lock(*mutex());
- //lock_tx();
+ {
+ synchro::lock_guard<Mutex> lock(*mutex());
          bloom().insert((std::size_t)&in);
- //unlock_tx();
          }
          writeList().insert(tx_pair((base_transaction_object*)&in, 0));
       }
@@ -1078,10 +1189,9 @@
       //-----------------------------------------------------------------------
       else
       {
- { synchro::lock_guard<Mutex> lock(*mutex());
- //lock_tx();
+ {
+ synchro::lock_guard<Mutex> lock(*mutex());
          bloom().insert((std::size_t)&in);
- //unlock_tx();
          }
          // check the ENTIRE write container for this piece of memory in the
          // second location. If it's there, it means we made a copy of a piece
@@ -1099,6 +1209,66 @@
    }
 
    //--------------------------------------------------------------------------
+ template <typename T>
+ void deferred_delete_tx_array(T *in, std::size_t size)
+ {
+ if (forced_to_abort())
+ {
+ deferred_abort(true);
+ throw aborted_tx("");
+ }
+ //-----------------------------------------------------------------------
+ // if this memory is true memory, not transactional, we add it to our
+ // deleted list and we're done
+ //-----------------------------------------------------------------------
+ bool all_valid = true;
+ for (int i=size-1; i>=0; --i) {
+ if (in[i].transaction_thread() == invalid_thread_id()) {
+ all_valid=false;
+ break;
+ }
+ }
+ if (all_valid) {
+ {
+ synchro::lock_guard<Mutex> lock(*mutex());
+ for (int i=size-1; i>=0; --i) {
+ bloom().insert((std::size_t)(&in[i]));
+ }
+ }
+ for (int i=size-1; i>=0; --i) {
+ writeList().insert(tx_pair((base_transaction_object*)(&in[i]), 0));
+ }
+ }
+ //-----------------------------------------------------------------------
+ // this isn't real memory, it's transactional memory. But the good news is,
+ // the real version has to be in our write list somewhere, find it, add
+ // both items to the deletion list and exit
+ //-----------------------------------------------------------------------
+ else
+ {
+ {
+ synchro::lock_guard<Mutex> lock(*mutex());
+ for (int i=size-1; i>=0; --i) {
+ bloom().insert((std::size_t)(&in[i]));
+ }
+ }
+ // check the ENTIRE write container for this piece of memory in the
+ // second location. If it's there, it means we made a copy of a piece
+ for (int i=size-1; i>=0; --i)
+ for (WriteContainer::iterator j = writeList().begin(); writeList().end() != j; ++j)
+ {
+ if (j->second == (base_transaction_object*)(&in[i]))
+ {
+ writeList().insert(tx_pair(j->first, 0));
+ deletedMemoryList().push_back(detail::make(j->first));
+ }
+ }
+ }
+
+ deletedMemoryList().push_back(detail::make_array(in, size));
+ }
+
+ //--------------------------------------------------------------------------
    void verifyReadMemoryIsValidWithGlobalMemory();
    void verifyWrittenMemoryIsValidWithGlobalMemory();
 
@@ -1999,20 +2169,11 @@
 #define before_retry catch (boost::stm::aborted_tx &)
 #define end_atom catch (boost::stm::aborted_tx &) {}
 
-#define BOOST_STM_NEW(T, P) \
- ((T).throw_if_forced_to_abort_on_new(), \
- (T).as_new(new P))
-
-#define BOOST_STM_NEW_1(P) \
- ((boost::stm::current_transaction()!=0)?BOOST_STM_NEW(*boost::stm::current_transaction(), P):new P)
-
 } // stm namespace
 } // boost namespace
 
 #include <boost/stm/detail/transaction_impl.hpp>
 #include <boost/stm/detail/latm_general_impl.hpp>
-//#include <boost/stm/synch/auto_lock.hpp>
-//#include <boost/stm/tx_ptr.hpp>
 
 ///////////////////////////////////////////////////////////////////////////////
 #endif // BOOST_STM_TRANSACTION__HPP

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 2009-11-07 16:28:19 EST (Sat, 07 Nov 2009)
@@ -75,7 +75,7 @@
         thread_initializer thi;
         for(int i=10; i>0;--i)
         {
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
                 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);
- } end_atom
+ } BOOST_STM_END_ATOMIC
             catch(...) {
                 cerr << "aborted"<< endl;
             }
@@ -101,7 +101,7 @@
 
 
 void create_db(bank* b, int nr_of_accounts){
- //atomic(_)
+ //BOOST_STM_ATOMIC(_) {
     {
         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;
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         a->Withdraw(10);
- } end_atom
+ } BOOST_STM_END_ATOMIC
 }
 void account_withdraw_thr() {
     thread_initializer thi;
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         make_wr_ptr(_,a)->Withdraw(10);
- } end_atom
+ } BOOST_STM_END_ATOMIC
 }
 
 void account_deposit_thr_basic() {
     thread_initializer thi;
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         a->Deposit(10);
- } end_atom
+ } BOOST_STM_END_ATOMIC
 }
 void account_deposit_thr() {
     thread_initializer thi;
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         make_wr_ptr(_,a)->Deposit(10);
- } end_atom
+ } BOOST_STM_END_ATOMIC
 }
 
 int test_account() {
@@ -157,17 +157,17 @@
 
 void vector_int_assign_basic() {
     thread_initializer thi;
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         (*v)[0]+=10;
- } end_atom
+ } BOOST_STM_END_ATOMIC
 }
 
 void vector_int_assign() {
     thread_initializer thi;
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         wr_ptr<std::vector<int> > wrv(_,v);
         (*wrv)[0]+=10;
- } end_atom
+ } BOOST_STM_END_ATOMIC
 }
 
 int test_vector_int() {
@@ -218,9 +218,9 @@
     delete th1;
     //th2->join();
     //delete th2;
- atomic(_) {
- mybank->print_balance();
- } end_atom
+ BOOST_STM_ATOMIC(_) {
+ mybank->print_balance();
+ } BOOST_STM_END_ATOMIC
 #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 2009-11-07 16:28:19 EST (Sat, 07 Nov 2009)
@@ -27,48 +27,48 @@
 void inc() {
     thread_initializer thi;
 
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         ++counter;
- } end_atom
+ } BOOST_STM_END_ATOMIC
 }
 void decr() {
     thread_initializer thi;
 
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         --counter;
- } end_atom
+ } BOOST_STM_END_ATOMIC
 }
 bool check(int val) {
     //thread_initializer thi;
     bool res;
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         res =(*counter==val);
- } end_atom
+ } BOOST_STM_END_ATOMIC
     return res;
 }
 
 bool assign() {
     //thread_initializer thi;
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         counter=1;
         counter2=counter;
- } end_atom
+ } BOOST_STM_END_ATOMIC
     bool res;
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         res =(*counter==1) && (*counter2==1) && (counter==counter2) ;
- } end_atom
+ } BOOST_STM_END_ATOMIC
     return res;
 }
 
 bool test_const(stm::tx_obj<int> const& c) {
     //thread_initializer thi;
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         counter2=c;
- } end_atom
+ } BOOST_STM_END_ATOMIC
     bool res;
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         res =(c==counter2) ;
- } end_atom
+ } BOOST_STM_END_ATOMIC
     return res;
 }
 

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 2009-11-07 16:28:19 EST (Sat, 07 Nov 2009)
@@ -32,65 +32,65 @@
 void inc() {
     thread_initializer thi;
 
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         // ++(*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);
- } end_atom
+ } BOOST_STM_END_ATOMIC
 }
 void decr() {
     thread_initializer thi;
 
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         // --(*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);
- } end_atom
+ } BOOST_STM_END_ATOMIC
 }
 bool check(int val) {
     //thread_initializer thi;
     bool res;
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         // *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);
- } end_atom
+ } BOOST_STM_END_ATOMIC
     return res;
 }
 
 bool assign() {
     //thread_initializer thi;
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         // *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;
- } end_atom
+ } BOOST_STM_END_ATOMIC
     bool res=true;
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         //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));
- } end_atom
+ } BOOST_STM_END_ATOMIC
     return res;
 }
 #if 0
 bool test_const(tx_int_const_ptr& const ptr) {
     //thread_initializer thi;
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         write_ptr<tx_int_const_ptr> tx_counter_const_ptr_ptr(_, counter_const_ptr);
         tx_counter_const_ptr_ptr=ptr;
- } end_atom
+ } BOOST_STM_END_ATOMIC
     bool res=true;
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         //res =(c==counter2) ;
- } end_atom
+ } BOOST_STM_END_ATOMIC
     return res;
 }
 #endif
@@ -98,7 +98,7 @@
 int test_counter() {
     atomic(_) {
         write_ptr<tx_int_ptr> tx_counter_ptr_ptr(_, counter_ptr);
- *tx_counter_ptr_ptr=BOOST_STM_NEW(_, tx_int());
+ *tx_counter_ptr_ptr=BOOST_STM_TX_NEW_PTR(_, tx_int());
     } end_atom
     thread th1(inc);
     thread th2(decr);

Modified: sandbox/stm/branches/vbe/libs/stm/example/list.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/example/list.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/example/list.cpp 2009-11-07 16:28:19 EST (Sat, 07 Nov 2009)
@@ -55,8 +55,8 @@
     tx_ptr<list_node<T> > head_;
     tx_ptr<std::size_t> size_;
     list()
- : head_(BOOST_STM_NEW_1(transactional_object<list_node<T> >()))
- , size_(BOOST_STM_NEW_1(transactional_object<std::size_t>(0)))
+ : head_(BOOST_STM_NEW_PTR(transactional_object<list_node<T> >()))
+ , size_(BOOST_STM_NEW_PTR(transactional_object<std::size_t>(0)))
     {
             std::cout << "list().head_" << *head_.get() << std::endl;
             std::cout << "list().size_" << *size_.get() << std::endl;
@@ -96,7 +96,7 @@
                 cerr << __LINE__ << " inserting" << endl;
                 wr_ptr<list_node<T> > insert_point(_,prev);
                 cerr << __LINE__ << " inserting" << endl;
- insert_point->next_=BOOST_STM_NEW(_,transactional_object<list_node<T> >(val, curr));
+ insert_point->next_=BOOST_STM_TX_NEW_PTR(_,transactional_object<list_node<T> >(val, curr));
                 cerr << __LINE__ << " inserting" << endl;
                 //wr_ptr<std::size_t > size_tx(_,size_);
                 //cerr << __LINE__ << " inserting" << endl;
@@ -166,7 +166,7 @@
     //l=boost::stm::make_tx_ptr<test::list<int> >();
     atomic(_) {
         cerr << __LINE__ << " create" << endl;
- l=BOOST_STM_NEW(_,transactional_object<test::list<int> >());
+ l=BOOST_STM_TX_NEW_PTR(_,transactional_object<test::list<int> >());
         cerr << __LINE__ << " create" << endl;
         cerr << " create size " << l->size() << endl;
         //cerr << " insert " << l.get() << endl;

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 2009-11-07 16:28:19 EST (Sat, 07 Nov 2009)
@@ -27,59 +27,59 @@
 void inc() {
     thread_initializer thi;
 
- atomic(t) {
+ BOOST_STM_ATOMIC(_) {
         non_tx::wr_ptr<int> tx_counter(t, counter);
         ++(*tx_counter);
- } end_atom
+ } BOOST_STM_END_ATOMIC
 }
 void decr() {
     thread_initializer thi;
 
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         non_tx::wr_ptr<int> tx_counter(_, counter);
         --(*tx_counter);
- } end_atom
+ } BOOST_STM_END_ATOMIC
 }
 bool check(int val) {
     //thread_initializer thi;
     bool res;
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         non_tx::rd_ptr<int> tx_counter(_, counter);
         res =(*tx_counter==val);
- } end_atom
+ } BOOST_STM_END_ATOMIC
     return res;
 }
 
 bool assign() {
     //thread_initializer thi;
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         non_tx::wr_ptr<int> tx_counter(_, counter);
         non_tx::wr_ptr<int> tx_counter2(_, counter2);
         *tx_counter=1;
         *tx_counter2=*tx_counter;
- } end_atom
+ } BOOST_STM_END_ATOMIC
     bool res;
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         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) ;
- } end_atom
+ } BOOST_STM_END_ATOMIC
     return res;
 }
 
 bool test_const(int const& c) {
     //thread_initializer thi;
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         non_tx::rd_ptr<int> tx_c(_, c);
         non_tx::wr_ptr<int> tx_counter2(_, counter2);
         *tx_counter2=*tx_c;
- } end_atom
+ } BOOST_STM_END_ATOMIC
     bool res;
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         non_tx::rd_ptr<int> tx_c(_, c);
         non_tx::wr_ptr<int> tx_counter2(_, counter2);
         res =(*tx_c==*tx_counter2) ;
- } end_atom
+ } BOOST_STM_END_ATOMIC
     return res;
 }
 

Deleted: sandbox/stm/branches/vbe/libs/stm/example/numeric.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/example/numeric.cpp 2009-11-07 16:28:19 EST (Sat, 07 Nov 2009)
+++ (empty file)
@@ -1,159 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-//
-// (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 <assert.h>
-#include <list>
-#include <iostream>
-#include <stdlib.h>
-
-using namespace std;
-using namespace boost;
-
-stm::tx::int_t counter(0);
-stm::tx::int_t counter2(0);
-
-void inc() {
- stm::thread_initializer thi;
-
- atomic(_) {
- ++counter;
- } end_atom
-}
-void inc1() {
- stm::thread_initializer thi;
-
- atomic(_) {
- counter+=1;
- } end_atom
-}
-void decr() {
- stm::thread_initializer thi;
-
- atomic(_) {
- --counter;
- } end_atom
-}
-bool check(int val) {
- //thread_initializer thi;
- atomic(_) {
- BOOST_STM_TX_RETURN(_, (counter==val));
- } end_atom
- return false;
-}
-
-bool test_equal() {
- //thread_initializer thi;
- atomic(_) {
- counter=1;
- counter2=2;
- BOOST_STM_TX_GOTO(_, label1);
- counter2=3;
- } end_atom
- label1:
- atomic(_) {
- counter=2;
- //assert(counter==counter2);
- BOOST_STM_TX_RETURN(_, (counter==counter2));
- } end_atom
- return false;
-}
-
-bool test_assign() {
- //thread_initializer thi;
- atomic(_) {
- counter=1;
- counter2=counter;
- BOOST_STM_CONTINUE;
- counter2=3;
- } end_atom
- atomic(_) {
- //assert((counter==1) && (counter2==1) && (counter==counter2));
- BOOST_STM_TX_RETURN(_, (counter==1) && (counter2==1) && (counter==counter2)) ;
- } end_atom
- return false;
-}
-
-bool test_less() {
- //thread_initializer thi;
- atomic(_) {
- counter=1;
- counter2=2;
- BOOST_STM_BREAK;
- counter2=3;
- } end_atom
- atomic(_) {
- //assert(counter<counter2);
- BOOST_STM_TX_RETURN(_, (counter<counter2)) ;
- } end_atom
- return false;
-}
-
-bool test_le() {
- //thread_initializer thi;
- atomic(_) {
- counter=1;
- counter2=1;
- } end_atom
- atomic(_) {
- //assert(counter<=counter2);
- BOOST_STM_TX_RETURN(_, (counter<=counter2)) ;
- } end_atom
- return false;
-}
-
-bool test_const(stm::tx::numeric<int> const& c) {
- //thread_initializer thi;
- atomic(_) {
- counter2=c;
- } end_atom
- use_atomic(_) {
- //assert(c==counter2);
- BOOST_STM_TX_RETURN(_, (c==counter2)) ;
- }
- return false;
-}
-
-int test_all() {
-
- thread th1(inc);
- thread th2(decr);
- thread th3(inc1);
- thread th4(inc);
-
- th1.join();
- th2.join();
- th3.join();
- th4.join();
-
- int fails=0;
- fails += !check(2);
- fails += !test_equal();
- fails += !test_assign();
- fails += !test_less();
- fails += !test_le();
- fails += !test_const(counter);
- return fails;
-}
-
-int main() {
- stm::transaction::enable_dynamic_priority_assignment();
- stm::transaction::do_deferred_updating();
- stm::transaction::initialize();
- stm::thread_initializer thi;
-
- return test_all();
-
-}

Added: sandbox/stm/branches/vbe/libs/stm/example/tx/array.cpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/libs/stm/example/tx/array.cpp 2009-11-07 16:28:19 EST (Sat, 07 Nov 2009)
@@ -0,0 +1,96 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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 <assert.h>
+#include <list>
+#include <iostream>
+#include <stdlib.h>
+
+using namespace std;
+using namespace boost;
+
+
+bool test_array() {
+ {
+ int v[2];
+ int * p;
+ p = &v[0];
+ *p=1;
+ p = v;
+ ++p;
+ *p=2;
+ }
+ stm::tx::int_t v[2];
+ stm::tx::pointer<stm::tx::int_t > p;
+ BOOST_STM_ATOMIC(_) {
+ p = &v[0];
+ *p=1;
+ p = v;
+ ++p;
+ *p=2;
+ } BOOST_STM_END_ATOMIC
+ return (v[0]==1) && (v[1]==2);
+}
+
+bool test_array_ptr() {
+ {
+ int * v= new int[2];
+ int * p;
+ p = &v[0];
+ p = v;
+ ++p;
+ }
+ stm::tx::pointer<stm::tx::int_t > v;
+ BOOST_STM_ATOMIC(_) {
+ 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
+
+ #if 0
+ {
+ stm::tx::pointer<stm::tx::int_t > v= BOOST_STM_NEW_ARRAY(2, stm::tx::int_t);
+
+ stm::tx::pointer<stm::tx::int_t > p;
+ p = &v[0];
+ p = v;
+ ++p;
+ }
+ #endif
+ bool res=true;
+ BOOST_STM_RETURN(res);
+ return false;
+}
+
+
+int test_all() {
+
+ int fails=0;
+ //fails += !test_array();
+ fails += !test_array_ptr();
+ return fails;
+}
+
+int main() {
+ stm::transaction::enable_dynamic_priority_assignment();
+ stm::transaction::do_deferred_updating();
+ stm::transaction::initialize();
+ stm::thread_initializer thi;
+ return test_all();
+}

Added: sandbox/stm/branches/vbe/libs/stm/example/tx/numeric.cpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/libs/stm/example/tx/numeric.cpp 2009-11-07 16:28:19 EST (Sat, 07 Nov 2009)
@@ -0,0 +1,159 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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 <assert.h>
+#include <list>
+#include <iostream>
+#include <stdlib.h>
+
+using namespace std;
+using namespace boost;
+
+stm::tx::int_t counter(0);
+stm::tx::int_t counter2(0);
+
+void inc() {
+ stm::thread_initializer thi;
+
+ BOOST_STM_ATOMIC(_) {
+ ++counter;
+ } BOOST_STM_END_ATOMIC
+}
+void inc1() {
+ stm::thread_initializer thi;
+
+ BOOST_STM_ATOMIC(_) {
+ counter+=1;
+ } BOOST_STM_END_ATOMIC
+}
+void decr() {
+ stm::thread_initializer thi;
+
+ BOOST_STM_ATOMIC(_) {
+ --counter;
+ } BOOST_STM_END_ATOMIC
+}
+bool check(int val) {
+ //thread_initializer thi;
+ BOOST_STM_ATOMIC(_) {
+ BOOST_STM_TX_RETURN(_, (counter==val));
+ } BOOST_STM_END_ATOMIC
+ return false;
+}
+
+bool test_equal() {
+ //thread_initializer thi;
+ BOOST_STM_ATOMIC(_) {
+ counter=1;
+ counter2=2;
+ BOOST_STM_TX_GOTO(_, label1);
+ counter2=3;
+ } BOOST_STM_END_ATOMIC
+ label1:
+ BOOST_STM_ATOMIC(_) {
+ counter=2;
+ //assert(counter==counter2);
+ BOOST_STM_TX_RETURN(_, (counter==counter2));
+ } BOOST_STM_END_ATOMIC
+ return false;
+}
+
+bool test_assign() {
+ //thread_initializer thi;
+ BOOST_STM_ATOMIC(_) {
+ counter=1;
+ counter2=counter;
+ BOOST_STM_CONTINUE;
+ counter2=3;
+ } BOOST_STM_END_ATOMIC
+ BOOST_STM_ATOMIC(_) {
+ //assert((counter==1) && (counter2==1) && (counter==counter2));
+ BOOST_STM_TX_RETURN(_, (counter==1) && (counter2==1) && (counter==counter2)) ;
+ } BOOST_STM_END_ATOMIC
+ return false;
+}
+
+bool test_less() {
+ //thread_initializer thi;
+ BOOST_STM_ATOMIC(_) {
+ counter=1;
+ counter2=2;
+ BOOST_STM_BREAK;
+ counter2=3;
+ } BOOST_STM_END_ATOMIC
+ BOOST_STM_ATOMIC(_) {
+ //assert(counter<counter2);
+ BOOST_STM_TX_RETURN(_, (counter<counter2)) ;
+ } BOOST_STM_END_ATOMIC
+ return false;
+}
+
+bool test_le() {
+ //thread_initializer thi;
+ BOOST_STM_ATOMIC(_) {
+ counter=1;
+ counter2=1;
+ } BOOST_STM_END_ATOMIC
+ BOOST_STM_ATOMIC(_) {
+ //assert(counter<=counter2);
+ BOOST_STM_TX_RETURN(_, (counter<=counter2)) ;
+ } BOOST_STM_END_ATOMIC
+ return false;
+}
+
+bool test_const(stm::tx::numeric<int> const& c) {
+ //thread_initializer thi;
+ BOOST_STM_ATOMIC(_) {
+ counter2=c;
+ } BOOST_STM_END_ATOMIC
+ BOOST_STM_ATOMIC(_) {
+ //assert(c==counter2);
+ BOOST_STM_TX_RETURN(_, (c==counter2)) ;
+ } BOOST_STM_END_ATOMIC
+ return false;
+}
+
+int test_all() {
+
+ thread th1(inc);
+ thread th2(decr);
+ thread th3(inc1);
+ thread th4(inc);
+
+ th1.join();
+ th2.join();
+ th3.join();
+ th4.join();
+
+ int fails=0;
+ fails += !check(2);
+ fails += !test_equal();
+ fails += !test_assign();
+ fails += !test_less();
+ fails += !test_le();
+ fails += !test_const(counter);
+ return fails;
+}
+
+int main() {
+ stm::transaction::enable_dynamic_priority_assignment();
+ stm::transaction::do_deferred_updating();
+ stm::transaction::initialize();
+ stm::thread_initializer thi;
+
+ return test_all();
+
+}

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 2009-11-07 16:28:19 EST (Sat, 07 Nov 2009)
@@ -22,12 +22,9 @@
 using namespace std;
 using namespace boost;
 
-stm::tx::int_t counter(0);
-stm::tx::int_t counter2(0);
-
 struct A {
     A() : i(0), ptr(&i) {
-
+
     }
     stm::tx::int_t i;
     stm::tx::pointer<stm::tx::int_t> const ptr;
@@ -70,10 +67,10 @@
     stm::tx::pointer<const int> const cpc = pc;
     //cpc=pc2; // this must not compile
     stm::tx::pointer<stm::tx::pointer<const int> > ppc;
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         pc=&cj;
     } end_atom
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         BOOST_STM_TX_RETURN(_, (pc==&cj)&&(*pc==20)&&(*cpc==10));
     } end_atom
     return false;
@@ -87,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;
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         pc=pc2;
- } end_atom
- atomic(_) {
+ } BOOST_STM_END_ATOMIC
+ BOOST_STM_ATOMIC(_) {
         BOOST_STM_TX_RETURN(_, (pc==&cj)&&(*pc==20)&&(*cpc==10));
- } end_atom
+ } BOOST_STM_END_ATOMIC
     return false;
 }
 
@@ -101,107 +98,37 @@
     stm::tx::int_t i;
     stm::tx::pointer<stm::tx::int_t > p;
     stm::tx::pointer<stm::tx::int_t > const cp = &i;
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         i=5;
         p=&i;
- } end_atom
- atomic(_) {
+ } BOOST_STM_END_ATOMIC
+ BOOST_STM_ATOMIC(_) {
         BOOST_STM_TX_RETURN(_, (i==5)&&(p==&i));
- } end_atom
+ } BOOST_STM_END_ATOMIC
     return false;
 }
 
 bool test_ptr_to_tx_assignment() {
     A a;
     B b;
- atomic(_) {
+ BOOST_STM_ATOMIC(_) {
         b.a_ptr=&a;
         b.a_ptr->i =1;
- } end_atom
- atomic(_) {
+ } BOOST_STM_END_ATOMIC
+ BOOST_STM_ATOMIC(_) {
         BOOST_STM_TX_RETURN(_, (b.a_ptr->i==1)&&(*b.a_ptr->ptr==1));
- } end_atom
- return false;
-}
-
-bool test_array() {
- {
- int v[2];
- int * p;
- p = &v[0];
- *p=1;
- p = v;
- ++p;
- *p=2;
- }
- stm::tx::int_t v[2];
- stm::tx::pointer<stm::tx::int_t > p;
- atomic(_) {
- p = &v[0];
- *p=1;
- p = v;
- ++p;
- *p=2;
- } end_atom
- return (v[0]==1) && (v[1]==2);
-}
-
-bool test_array_ptr() {
- {
- int * v= new int[2];
- int * p;
- p = &v[0];
- p = v;
- ++p;
- }
- stm::tx::pointer<stm::tx::int_t > v;
- atomic(_) {
- v= BOOST_STM_TX_NEW_ARRAY(_,2, stm::tx::int_t);
- //_.throw_if_forced_to_abort_on_new();
- //v= _.as_new_array(new stm::tx::int_t[2], 2);
-
-
- stm::tx::pointer<stm::tx::int_t > p;
- p = &v[0];
- p = v;
- //++p;
- } end_atom
-
- #if 0
- {
- stm::tx::pointer<stm::tx::int_t > v= BOOST_STM_NEW_ARRAY(2, stm::tx::int_t);
-
- stm::tx::pointer<stm::tx::int_t > p;
- p = &v[0];
- p = v;
- ++p;
- }
- #endif
- bool res=true;
- BOOST_STM_RETURN(res);
+ } BOOST_STM_END_ATOMIC
     return false;
 }
 
-
 int test_all() {
 
- //thread th1(inc);
- //thread th2(decr);
- //thread th3(inc1);
- //thread th4(inc);
-
- //th1.join();
- //th2.join();
- //th3.join();
- //th4.join();
 
     int fails=0;
- //fails += !test_ptr_to_tx_const();
- //fails += !test_ptr_to_tx();
- //fails += !test_ptr_to_const();
- //fails += !test_ptr_to_tx_assignment();
- //fails += !test_array();
- fails += !test_array_ptr();
+ fails += !test_ptr_to_tx_const();
+ fails += !test_ptr_to_tx();
+ fails += !test_ptr_to_const();
+ fails += !test_ptr_to_tx_assignment();
     return fails;
 }
 

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 2009-11-07 16:28:19 EST (Sat, 07 Nov 2009)
@@ -211,7 +211,8 @@
             [ run ../example/counter.cpp ]
             # fails sometimes
             # assertion "res==0" failed: file "../../../boost/synchro/pthread/mutex.hpp", line 52
- [ run ../example/numeric.cpp ]
+ [ run ../example/tx/numeric.cpp ]
+ [ run ../example/tx/array.cpp ]
             [ run ../example/tx/pointer.cpp ]
             [ run ../example/counter_ptr.cpp ]
             # fails sometimes
@@ -250,7 +251,7 @@
             ########### fails sometimes
             [ run stm : -bench rbtree -def -threads 4 -inserts 100 : : : rbtree_def_t4_i100 ]
 
- ########### fails
+ ########### fails sometimes 19:00 091107
             [ run stm : -bench ll -dir -threads 2 -inserts 100 -latm tx : : : ll_dir_t2_tx_i100 ]
 
             ########### fails sometimes


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