Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56657 - in sandbox/stm/branches/vbe/libs/stm: build example src test
From: vicente.botet_at_[hidden]
Date: 2009-10-08 15:36:18


Author: viboes
Date: 2009-10-08 15:36:17 EDT (Thu, 08 Oct 2009)
New Revision: 56657
URL: http://svn.boost.org/trac/boost/changeset/56657

Log:
TBoost.Stm vbe
* build
* adding test/non_tx_counter.cpp

Added:
   sandbox/stm/branches/vbe/libs/stm/example/non_tx_counter.cpp (contents, props changed)
Text files modified:
   sandbox/stm/branches/vbe/libs/stm/build/Jamfile.v2 | 3 ++-
   sandbox/stm/branches/vbe/libs/stm/example/bank.cpp | 1 +
   sandbox/stm/branches/vbe/libs/stm/example/counter_ptr.cpp | 2 +-
   sandbox/stm/branches/vbe/libs/stm/src/except_and_back_off_on_abort_notice_cm.cpp | 2 +-
   sandbox/stm/branches/vbe/libs/stm/src/transaction.cpp | 16 ++++++++--------
   sandbox/stm/branches/vbe/libs/stm/test/Jamfile.v2 | 7 +++----
   6 files changed, 16 insertions(+), 15 deletions(-)

Modified: sandbox/stm/branches/vbe/libs/stm/build/Jamfile.v2
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/build/Jamfile.v2 (original)
+++ sandbox/stm/branches/vbe/libs/stm/build/Jamfile.v2 2009-10-08 15:36:17 EDT (Thu, 08 Oct 2009)
@@ -206,7 +206,8 @@
 
 static-lib boost_STM
 # : bloom_filter.cpp contention_manager.cpp transaction.cpp except_and_back_off_on_abort_notice_cm.cpp interthreads_sources
- : bloom_filter.cpp contention_manager.cpp transaction.cpp
+ : bloom_filter.cpp contention_manager.cpp transaction.cpp except_and_back_off_on_abort_notice_cm.cpp
+# : bloom_filter.cpp contention_manager.cpp transaction.cpp
 # ../../../../libs/thread/build//boost_thread
     : <conditional>@requirements
     :

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-10-08 15:36:17 EDT (Thu, 08 Oct 2009)
@@ -18,6 +18,7 @@
 #include <vector>
 #include <list>
 #include <stdlib.h>
+
 #define foreach BOOST_FOREACH
 
 using namespace std;

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-10-08 15:36:17 EDT (Thu, 08 Oct 2009)
@@ -111,7 +111,7 @@
     th4.join();
     
     int fails=0;
- fails += check(1);
+ fails += check(2);
     fails += !assign();
     //fails += !test_const(counter);
     return fails;

Added: sandbox/stm/branches/vbe/libs/stm/example/non_tx_counter.cpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/libs/stm/example/non_tx_counter.cpp 2009-10-08 15:36:17 EDT (Thu, 08 Oct 2009)
@@ -0,0 +1,116 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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;
+
+int counter;
+int counter2;
+
+void inc() {
+ thread_initializer thi;
+
+ use_atomic(t) {
+ non_tx::wr_ptr<int> tx_counter(t, counter);
+ ++(*tx_counter);
+ }
+}
+void decr() {
+ thread_initializer thi;
+
+ use_atomic(_) {
+ non_tx::wr_ptr<int> tx_counter(_, counter);
+ --(*tx_counter);
+ }
+}
+bool check(int val) {
+ //thread_initializer thi;
+ bool res;
+ use_atomic(_) {
+ non_tx::rd_ptr<int> tx_counter(_, counter);
+ res =(*tx_counter==val);
+ }
+ return res;
+}
+
+bool assign() {
+ //thread_initializer thi;
+ use_atomic(_) {
+ non_tx::wr_ptr<int> tx_counter(_, counter);
+ non_tx::wr_ptr<int> tx_counter2(_, counter2);
+ *tx_counter=1;
+ *tx_counter2=*tx_counter;
+ }
+ bool res;
+ use_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) ;
+ }
+ return res;
+}
+
+bool test_const(int const& c) {
+ //thread_initializer thi;
+ use_atomic(_) {
+ non_tx::rd_ptr<int> tx_c(_, c);
+ non_tx::wr_ptr<int> tx_counter2(_, counter2);
+ *tx_counter2=*tx_c;
+ }
+ bool res;
+ use_atomic(_) {
+ non_tx::rd_ptr<int> tx_c(_, c);
+ non_tx::wr_ptr<int> tx_counter2(_, counter2);
+ res =(*tx_c==*tx_counter2) ;
+ }
+ return res;
+}
+
+int test_counter() {
+ //counter=make_tx_ptr<int>(0);
+
+ thread th1(inc);
+ thread th2(decr);
+ thread th3(inc);
+ thread th4(inc);
+
+ th1.join();
+ th2.join();
+ th3.join();
+ th4.join();
+
+ bool fails=!check(2);
+ fails = fails || !assign();
+ fails = 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));
+
+ test_counter();
+
+ return 0;
+
+}

Modified: sandbox/stm/branches/vbe/libs/stm/src/except_and_back_off_on_abort_notice_cm.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/src/except_and_back_off_on_abort_notice_cm.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/src/except_and_back_off_on_abort_notice_cm.cpp 2009-10-08 15:36:17 EDT (Thu, 08 Oct 2009)
@@ -13,7 +13,7 @@
 
 
 #include <boost/stm/transaction.hpp>
-#include <boost/stm/except_and_back_off_on_abort_notice_cm.hpp>
+#include <boost/stm/contention_managers/except_and_back_off_on_abort_notice_cm.hpp>
 
 namespace boost { namespace stm {
 

Modified: sandbox/stm/branches/vbe/libs/stm/src/transaction.cpp
==============================================================================
--- sandbox/stm/branches/vbe/libs/stm/src/transaction.cpp (original)
+++ sandbox/stm/branches/vbe/libs/stm/src/transaction.cpp 2009-10-08 15:36:17 EDT (Thu, 08 Oct 2009)
@@ -12,7 +12,7 @@
 //////////////////////////////////////////////////////////////////////////////
 
 #include <boost/stm/transaction.hpp>
-#include <boost/stm/non_tx_smart_ptr.hpp>
+#include <boost/stm/non_tx/smart_ptr.hpp>
 #include <boost/stm/contention_manager.hpp>
 #include <iostream>
 
@@ -69,7 +69,7 @@
 // third param = # of increases before resetting
 ///////////////////////////////////////////////////////////////////////////////
 #if defined(BOOST_STM_CM_STATIC_CONF)
-#if defined(BOOST_STM_CM_STATIC_CONF_ExceptAndBackOffOnAbortNoticeCM)
+#if defined(BOOST_STM_CM_STATIC_CONF_except_and_back_off_on_abort_notice_cm)
    //boost::stm::contention_manager_type boost::stm::transaction::cm_(0, 0, 0);
    int boost::stm::except_and_back_off_on_abort_notice_cm::sleepTime_=0;
    int const boost::stm::except_and_back_off_on_abort_notice_cm::kSleepFactorIncrease_=0;
@@ -158,7 +158,7 @@
 ///////////////////////////////////////////////////////////////////////////////
 void transaction::initialize_thread()
 {
- lock_general_access();
+ lock(general_lock());
 
    //--------------------------------------------------------------------------
    // WARNING: before you think lock_all_mutexes() does not make sense, make
@@ -419,14 +419,14 @@
 
    //--------------------------------------------------------------------------
 
- unlock_general_access();
+ unlock(general_lock());
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 void transaction::terminate_thread()
 {
- lock_general_access();
- lock_inflight_access();
+ lock(general_lock());
+ lock(inflight_lock());
 
    size_t threadId = THREAD_ID;
 
@@ -525,8 +525,8 @@
 #endif
 
 
- unlock_inflight_access();
- unlock_general_access();
+ unlock(inflight_lock());
+ unlock(general_lock());
 }
 
 }}

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-10-08 15:36:17 EDT (Thu, 08 Oct 2009)
@@ -17,10 +17,8 @@
 project
     : requirements
 # <library>/boost/test//boost_unit_test_framework/<link>static
-# <library>/boost/thread//boost_thread/<link>static
-# <library>/boost_1_39_0/libs/test/build//boost_unit_test_framework/<link>static
         <library>../build//boost_STM/<link>static
- <library>/boost_1_39_0/libs/thread/build//boost_thread/<link>static
+ <library>/boost/thread//boost_thread/<link>static
 
         <include>.
         <include>../../..
@@ -48,6 +46,7 @@
           [ run ../example/bank.cpp ]
           #[ run ../example/list.cpp ]
           [ run ../example/counter.cpp ]
+ [ run ../example/numeric.cpp ]
           [ run ../example/counter_ptr.cpp ]
- [ run ../example/non_tx_counter.cpp ]
+ #[ run ../example/non_tx_counter.cpp ]
     ;


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