|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r57647 - in sandbox/stm/branches/vbe: boost/stm/tx libs/stm/example/tx
From: vicente.botet_at_[hidden]
Date: 2009-11-14 10:19:14
Author: viboes
Date: 2009-11-14 10:19:13 EST (Sat, 14 Nov 2009)
New Revision: 57647
URL: http://svn.boost.org/trac/boost/changeset/57647
Log:
TBoost.STM vbe:
* Make tx/list.cpp work (there are yet some issues)
Text files modified:
sandbox/stm/branches/vbe/boost/stm/tx/mixin.hpp | 35 +++----
sandbox/stm/branches/vbe/boost/stm/tx/object.hpp | 10 +-
sandbox/stm/branches/vbe/boost/stm/tx/pointer.hpp | 29 +++---
sandbox/stm/branches/vbe/libs/stm/example/tx/list.cpp | 172 ++++++++++++++++++++++++++-------------
4 files changed, 146 insertions(+), 100 deletions(-)
Modified: sandbox/stm/branches/vbe/boost/stm/tx/mixin.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/tx/mixin.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/tx/mixin.hpp 2009-11-14 10:19:13 EST (Sat, 14 Nov 2009)
@@ -32,34 +32,31 @@
class mixin : public transaction_object< Final, Base >
{
protected:
-public:
T val_;
+public:
typedef mixin<Final, T, Base> this_type;
typedef Final final_type;
typedef T value_type;
//-----------------------------------------------------------------------------
mixin() : val_() {
- std::cerr << __LINE__ << " mixin val_=" << val_ << std::endl;
+ //std::cerr << __LINE__ << " mixin val_=" << val_ << std::endl;
}
- //
- //template<typename F, typename U>
- //mixin(mixin<F,U> const& r) : val_(r.value()) {
- // std::cerr << __LINE__ << " mixin val_=" << val_ << std::endl;
- //}
-
- //template<typename F, typename U>
mixin(mixin const& r) : val_(r.value()) {
- std::cerr << __LINE__ << " mixin val_=" << val_ << std::endl;
+ //std::cerr << __LINE__ << " mixin val_=" << val_ << std::endl;
+ }
+ template<typename F, typename U>
+ mixin(mixin<F,U> const& r) : val_(r.value()) {
+ //std::cerr << __LINE__ << " mixin val_=" << val_ << std::endl;
}
- // contructor from a convertible to T
- //template <typename U>
- //mixin(U v) : val_(v) {
- // std::cerr << __LINE__ << " mixin val_=" << v << std::endl;
- //}
mixin(T v) : val_(v) {
- std::cerr << __LINE__ << " mixin val_=" << v << std::endl;
+ //std::cerr << __LINE__ << " mixin val_=" << v << std::endl;
+ }
+ // contructor from a convertible to T
+ template <typename U>
+ mixin(U v) : val_(v) {
+ //std::cerr << __LINE__ << " mixin val_=" << v << std::endl;
}
operator T() const { return value(); }
@@ -88,17 +85,13 @@
tx->lock_and_abort();
throw aborted_transaction_exception("aborting transaction");
}
- this_type const * r=tx->read_ptr(this);
- std::cerr << __LINE__ << " mixin this=" << this << std::endl;
- std::cerr << __LINE__ << " mixin this.val_=" << this->val_ << std::endl;
- std::cerr << __LINE__ << " mixin read=" << r << std::endl;
- std::cerr << __LINE__ << " mixin val_=" << r->val_ << std::endl;
return tx->read(*this).val_;
}
return val_;
}
};
+
}}}
#endif //BOOST_STM_TX_MIXIN__HPP
Modified: sandbox/stm/branches/vbe/boost/stm/tx/object.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/tx/object.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/tx/object.hpp 2009-11-14 10:19:13 EST (Sat, 14 Nov 2009)
@@ -34,22 +34,22 @@
typedef mixin< object<T>, T > base_type;
//-----------------------------------------------------------------------------
object() : base_type() {
- std::cerr << __LINE__ << " object" << std::endl;
+ //std::cerr << __LINE__ << " object" << std::endl;
}
template<typename U>
object(object<U> const& r) : base_type(r) {
- std::cerr << __LINE__ << " object" << std::endl;
+ //std::cerr << __LINE__ << " object" << std::endl;
}
object(object const& r) : base_type(r) {
- std::cerr << __LINE__ << " object" << std::endl;
+ //std::cerr << __LINE__ << " object" << std::endl;
}
// contructor from a convertible to T
template <typename U>
object(U v) : base_type(v) {
- std::cerr << __LINE__ << " object" << std::endl;
+ //std::cerr << __LINE__ << " object" << std::endl;
}
object(T v) : base_type(v) {
- std::cerr << __LINE__ << " object" << std::endl;
+ //std::cerr << __LINE__ << " object" << std::endl;
}
};
Modified: sandbox/stm/branches/vbe/boost/stm/tx/pointer.hpp
==============================================================================
--- sandbox/stm/branches/vbe/boost/stm/tx/pointer.hpp (original)
+++ sandbox/stm/branches/vbe/boost/stm/tx/pointer.hpp 2009-11-14 10:19:13 EST (Sat, 14 Nov 2009)
@@ -35,22 +35,23 @@
public:
//-----------------------------------------------------------------------------
pointer() : base_type(static_cast<T*>(0)) {
- std::cerr << __LINE__ << " pointer" << std::endl;
+ //std::cerr << __LINE__ << " pointer" << std::endl;
}
- //template<class U>
- //pointer(pointer<U> const& r) : base_type(r) {
- // std::cerr << __LINE__ << " pointer" << std::endl;
- //}
- //pointer(pointer const& r) : base_type(r) {
- pointer(pointer const& r) : base_type(*((base_type const*)(&r))) {
- std::cerr << __LINE__ << " pointer" << std::endl;
- }
- //template <typename U>
- //pointer(U* v) : base_type(v) {
- // std::cerr << __LINE__ << " pointer" << std::endl;
- //}
+ //pointer(pointer const& r) : base_type(*((base_type const*)(&r))) {
+ pointer(pointer const& r) : base_type(r) {
+ //std::cerr << __LINE__ << " pointer" << std::endl;
+ }
+ template<class U>
+ pointer(pointer<U> const& r) : base_type(r) {
+ //std::cerr << __LINE__ << " pointer" << std::endl;
+ }
+
pointer(T* v) : base_type(v) {
- std::cerr << __LINE__ << " pointer" << std::endl;
+ //std::cerr << __LINE__ << " pointer" << std::endl;
+ }
+ template <typename U>
+ pointer(U* v) : base_type(v) {
+ //std::cerr << __LINE__ << " pointer" << std::endl;
}
T* operator->() const {
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 2009-11-14 10:19:13 EST (Sat, 14 Nov 2009)
@@ -28,22 +28,22 @@
public:
list_node() : value_(), next_()
- , embeddeds_()
-{}
+ , binds_()
+ {}
explicit list_node(T const &rhs)
: value_(rhs), next_() {}
- list_node(T const &rhs, tx::pointer<list_node<T> > next)
+ list_node(T const &rhs, list_node<T>* next)
: value_(rhs), next_(next) {}
// zero initialization for native types
void clear() { value_ = T(); next_ = 0; }
- std::list<base_transaction_object*>& binds() {return embeddeds_;}
- void bind(base_transaction_object* bto) {embeddeds_.push_back(bto);}
+ std::list<base_transaction_object*>& binds() {return binds_;}
+ void bind(base_transaction_object* bto) {binds_.push_back(bto);}
tx::object<T> value_;
tx::pointer<list_node<T> > next_;
- std::list<base_transaction_object*> embeddeds_;
+ std::list<base_transaction_object*> binds_;
};
template <typename OSTREAM, typename T>
@@ -65,8 +65,8 @@
: head_(BOOST_STM_NEW_PTR(list_node<T>()))
, size_(0)
{
- std::cout << "list().head=" << head_ << std::endl;
- std::cout << "list().size=" << size_ << std::endl;
+ //std::cout << "list().head=" << head_ << std::endl;
+ //std::cout << "list().size=" << size_ << std::endl;
}
~list() { }
@@ -82,47 +82,39 @@
// find the location to insert the node. if the value already exists, fail
//--------------------------------------------------------------------------
void insert(const T& val) {
- cerr << __LINE__ << " insert" << endl;
+ //cerr << __LINE__ << " * insert" << endl;
BOOST_STM_ATOMIC(_) {
- //for (boost::stm::transaction _; !_.committed() && _.restart(); _.end()) {
- cerr << __LINE__ << " insert head=" << head_.value() << endl;
- //tx::pointer<list_node<T> > prev(head_);
- list_node<T>* prev(head_);
- //tx::pointer<list_node<T> > curr(head_->next_);
- list_node<T> * curr(head_->next_);
+ list_node<T>* prev=head_;
+ list_node<T> * curr=head_->next_.value();
while (curr!=0) {
- cerr << __LINE__ << " curr" << curr << endl;
if (curr->value_ == val) return;
else if (curr->value_ > val) break;
prev = curr;
- curr = curr->next_;
+ curr = curr->next_.value();
}
- cerr << __LINE__ << " insert" << endl;
if (curr==0 || (curr->value_ > val)) {
- tx::pointer<list_node<T> > mod(prev);
- mod->next_=BOOST_STM_TX_NEW_PTR(_,list_node<T>(val, curr));
+ prev->next_=BOOST_STM_TX_NEW_PTR(_,list_node<T>(val, curr));
++size_;
- cerr << __LINE__ << " inserting" << endl;
-
}
} BOOST_STM_END_ATOMIC
catch (...) {
- cerr << __LINE__ << " insert" << endl;
+ cerr << __LINE__ << " * insert" << endl;
}
- cerr << __LINE__ << " insert" << endl;
+ //cerr << __LINE__ << " * insert" << endl;
}
// search function
bool lookup(const T& val) const {
- bool found = false;
+ cerr << __LINE__ << " * lookup val=" << val << endl;
BOOST_STM_ATOMIC(_) {
- tx::pointer<list_node<T> > curr=head_;
- curr = curr->next_;
+ list_node<T>* curr=head_->next_.value();
while (curr) {
+ cerr << __LINE__ << " * lookup curr->value_=" << curr->value_ << endl;
if (curr->value_ >= val) break;
- curr = curr->next_;
+ curr = curr->next_.value();
}
+ cerr << __LINE__ << " * lookup ret=" << ((curr) && (curr->value_ == val)) << endl;
BOOST_STM_RETURN((curr) && (curr->value_ == val));
} BOOST_STM_END_ATOMIC
catch (...) {
@@ -136,18 +128,19 @@
{
BOOST_STM_ATOMIC(_) {
// find the node whose val matches the request
- tx::pointer<list_node<T> > prev=head_;
- tx::pointer<list_node<T> > curr=prev->next_;
+ list_node<T>* prev=head_;
+ list_node<T>* curr=prev->next_.value();
while (curr) {
// if we find the node, disconnect it and end the search
if (curr->value_ == val) {
- prev->next_=curr->next_;
+ cerr << __LINE__ << " * remove found next=" << curr->next_.value() << endl;
+ prev->next_=curr->next_.value();
// delete curr...
- delete_ptr(_,curr);
+ BOOST_STM_TX_DELETE_PTR(_,curr);
--size_;
break;
} else if (curr->value_ > val) {
- // this means the search failed
+ cerr << __LINE__ << " * remove not found" << endl;
break;
}
prev = curr;
@@ -161,6 +154,7 @@
//--------------------------------------------------------------------------
test::list<int> l;
+test::list_node<int> n;
void create() {
BOOST_STM_ATOMIC(_) {
@@ -171,58 +165,116 @@
cerr << "aborted" << endl;
}
}
-void insert1() {
+bool check_size(std::size_t val) {
+ BOOST_STM_ATOMIC(_) {
+ BOOST_STM_RETURN(l.size()==val);
+ } BOOST_STM_END_ATOMIC
+ return false;
+}
+bool check_lookup(int val) {
+ BOOST_STM_ATOMIC(_) {
+ //cerr << " check_lookup " << l.lookup(val) << endl;
+ BOOST_STM_RETURN(l.lookup(val));
+ } BOOST_STM_END_ATOMIC
+ return false;
+}
+
+bool insert1() {
//thread_initializer thi;
- //BOOST_STM_ATOMIC(_) {
- cerr << __LINE__ << " try" << endl;
- cerr << __LINE__ << " insert1 size " << l.size() << endl;
- int val = 1;
+ BOOST_STM_ATOMIC(_) {
+ int val = 10;
l.insert(val);
- cerr << __LINE__ << " insert1 size " << l.size() << endl;
- //} BOOST_STM_END_ATOMIC
- //catch(...) {
- // cerr << __LINE__ << " aborted" << endl;
- //}
+ } BOOST_STM_END_ATOMIC
+ return check_size(1);
+}
+void insert1_th() {
+ thread_initializer thi;
+ BOOST_STM_ATOMIC(_) {
+ l.insert(1);
+ } BOOST_STM_END_ATOMIC
}
-void insert2() {
+void insert2_th() {
thread_initializer thi;
BOOST_STM_ATOMIC(_) {
l.insert(2);
} BOOST_STM_END_ATOMIC
}
-void insert3() {
+void remove2() {
+ //thread_initializer thi;
+ BOOST_STM_ATOMIC(_) {
+ l.remove(2);
+ } BOOST_STM_END_ATOMIC
+}
+
+void insert3_th() {
thread_initializer thi;
BOOST_STM_ATOMIC(_) {
l.insert(3);
} BOOST_STM_END_ATOMIC
}
-bool check_size(std::size_t val) {
+bool n1() {
BOOST_STM_ATOMIC(_) {
- BOOST_STM_RETURN(l.size()==val);
+ 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_RETURN(n.next_->value_==10);
+ } BOOST_STM_END_ATOMIC
+ return false;
+}
+
+bool n2() {
+ BOOST_STM_ATOMIC(_) {
+ n.next_->value_=12;
+ } BOOST_STM_END_ATOMIC
+ BOOST_STM_ATOMIC(_) {
+ BOOST_STM_RETURN(n.next_->value_==12);
} BOOST_STM_END_ATOMIC
return false;
}
+
+bool n3() {
+ //cerr << __LINE__ << " * n3" << endl;
+ BOOST_STM_ATOMIC(_) {
+ test::list_node<int>* prev =&n;
+ test::list_node<int>* curr =prev->next_.value();
+ 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_RETURN(n.next_->value_==10);
+ } BOOST_STM_END_ATOMIC
+ return false;
+}
+
int test_all() {
//create();
- insert1();
bool fails=false;
+ //fails= fails || !n1();
+ //fails= fails || !n2();
+ fails= fails || !n3();
//fails= fails || !check_size(0);
- #if 0
- thread th1(insert1);
- thread th2(insert2);
- thread th3(insert2);
- thread th4(insert3);
-
+ //fails= fails || !insert1();
+ thread th1(insert1_th);
+ thread th2(insert2_th);
+ //thread th3(insert2_th);
+ //thread th4(insert3_th);
+
th1.join();
th2.join();
- th3.join();
- th4.join();
- bool fails=false;
- //fails= !check_size(1);
- //boost::stm::delete_ptr(l);
- #endif
+ //th3.join();
+ //th4.join();
+ fails= fails || !check_lookup(1);
+ fails= fails || !check_lookup(2);
+ fails= fails || !check_size(2);
+ remove2();
+ fails= fails || !check_lookup(1);
+ //fails= fails || check_lookup(2);
+ fails= fails || !check_size(1);
+ #if 0
SLEEP(2);
+ #endif
return fails;
}
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