$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r59620 - in sandbox/stm/branches/vbe/libs/stm: example test
From: vicente.botet_at_[hidden]
Date: 2010-02-10 12:04:48
Author: viboes
Date: 2010-02-10 12:04:47 EST (Wed, 10 Feb 2010)
New Revision: 59620
URL: http://svn.boost.org/trac/boost/changeset/59620
Log:
Boost.STM/vbe: 
* Add embedded test
* remove txw tests
Added:
   sandbox/stm/branches/vbe/libs/stm/example/embed.cpp   (contents, props changed)
Text files modified: 
   sandbox/stm/branches/vbe/libs/stm/test/Jamfile.v2 |    37 +++++++++++++++++++++----------------   
   1 files changed, 21 insertions(+), 16 deletions(-)
Added: sandbox/stm/branches/vbe/libs/stm/example/embed.cpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/libs/stm/example/embed.cpp	2010-02-10 12:04:47 EST (Wed, 10 Feb 2010)
@@ -0,0 +1,176 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+    
+/*
+Should we enable embedded TO?
+
+* First, with coarse grained TO, we don't have any mean to force the user to don't embed TO
+* Second, it is natural to embed objects, so why not TO.
+* Third, with current implementation, embedded TO can fail
+
+* Should we provide only fine grained TO? This seems a rather big restriction, as there are objets for which fine grained are not adapted, e.g. string.
+
+* Is there an implementation that can make coarse grained TO be embedded?
+There is an implementation that coudl make works this.
+
+We will need to map intervals of shared address instead of address.
+
+When an embedding TO is writen, all the current embedded TO must be replaced.
+When a embedded TO is query, we need to see if there is already an embedding TO in the writer list.
+
+In addition we need to take care of smart pointers as the cached specific address can change.
+
+And of course we will need to change the conflic algorithm.
+
+interval_map : address -> {address, {smart_pointers, offset}*}
+
+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) // 
+            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 
+            update the cache with already written members
+            update smart pointers with new offset
+            concatenate smart pointers list            
+            
+        replace all the intervals by the new interval
+    else // not found
+        insert
+        return
+
+
+This introduce an intrusive pointer class.
+All this sems quite complex and will decreased the performance of 
+reads/writes and conflict detection.
+
+*/
+
+#include <boost/stm.hpp>
+
+using namespace std;
+using namespace boost;
+using namespace boost::stm;
+
+
+struct Inner : transaction_object<Inner> 
+{
+    Inner(): i(0) {}
+    int i;
+};
+
+struct Outer : transaction_object<Outer> 
+{
+    Outer(): e(), j(0) {}
+    Inner e;
+    int j;
+};
+
+
+  
+bool check_in_nested_fails() {
+    Outer obj;
+    BOOST_STM_ATOMIC(_) {
+        _.write(obj.e).i=1;
+        BOOST_STM_ATOMIC(_) {
+            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(_) {
+        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;    
+}  
+
+bool check_after_nested_fails() {
+    Outer obj;
+    BOOST_STM_ATOMIC(_) {
+        _.write(obj).j=0;
+        BOOST_STM_ATOMIC(_) {
+            _.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(_) {
+        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;    
+}  
+
+bool mod_outer_same_in_nested_fails() {
+    Outer obj;
+    BOOST_STM_ATOMIC(_) {
+        _.write(obj.e).i=1;
+        BOOST_STM_ATOMIC(_) {
+            _.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(_) {
+        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;    
+}  
+
+bool mod_inner_same_in_nested_and_check_after_fails() {
+    Outer obj;
+    BOOST_STM_ATOMIC(_) {
+        _.write(obj).e.i=1;
+        BOOST_STM_ATOMIC(_) {
+            _.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(_) {
+        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;    
+}  
+
+
+int main() {
+    transaction::enable_dynamic_priority_assignment();
+    transaction::do_deferred_updating();
+    transaction::initialize();
+    thread_initializer thi;
+
+    int res=0;
+    res+=!check_in_nested_fails();
+    res+=!check_after_nested_fails();
+    res+=!mod_outer_same_in_nested_fails();
+    res+=!mod_inner_same_in_nested_and_check_after_fails();
+    return res;
+
+}
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-10 12:04:47 EST (Wed, 10 Feb 2010)
@@ -186,6 +186,11 @@
             [ run stm : -bench list_hash_w_locks -dir -threads 4 -inserts 100 -latm tx : : : list_hash_w_locks_dir_tx_t4_i100 ]
     ;
 
+    alias embedded
+        :
+            [ run ../example/embed.cpp ]
+    ;
+
     alias examples_tx
         :
             [ compile-fail ../example/deep_singleton.cpp ]
@@ -200,21 +205,21 @@
             [ run ../example/tx/list_sp.cpp : : : : tx_list_sp ]
     ;
 
-    alias examples_txw
-        :
-            [ link ../example/bank.cpp ]
-
-            ########### fails
-            # /bin/sh: line 4:  2656 Segmentation fault      (core dumped) "bin/list.test/gcc-3.4.4/debug/threading-multi/list.exe" > "bin/list.test/gcc-3.4.4/debug/threading-multi/list.output" 2>&1
-            [ link ../example/list.cpp ]
-            [ link ../example/counter.cpp ]
-            # fails sometimes
-            # assertion "res==0" failed: file "../../../boost/synchro/pthread/mutex.hpp", line 52
-            [ run ../example/counter_ptr.cpp ]
-            # fails sometimes
-            # assertion "res==0" failed: file "../../../boost/synchro/pthread/mutex.hpp", line 52
-            #[ run ../example/non_tx_counter.cpp ]
-    ;
+    #alias examples_txw
+    #    :
+    #        [ link ../example/bank.cpp ]
+    #
+    #        ########### fails
+    #        # /bin/sh: line 4:  2656 Segmentation fault      (core dumped) "bin/list.test/gcc-3.4.4/debug/threading-multi/list.exe" > "bin/list.test/gcc-3.4.4/debug/threading-multi/list.output" 2>&1
+    #        [ link ../example/list.cpp ]
+    #        [ link ../example/counter.cpp ]
+    #        # fails sometimes
+    #        # assertion "res==0" failed: file "../../../boost/synchro/pthread/mutex.hpp", line 52
+    #        [ run ../example/counter_ptr.cpp ]
+    #        # fails sometimes
+    #        # assertion "res==0" failed: file "../../../boost/synchro/pthread/mutex.hpp", line 52
+    #        #[ run ../example/non_tx_counter.cpp ]
+    #;
 
     alias examples_non_tx
         :
@@ -225,7 +230,7 @@
 
     alias examples 
         : examples_tx 
-          examples_txw
+        #  examples_txw
         # examples_non_tx
         ;