|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r57030 - sandbox/stm/branches/vbe/libs/stm/example
From: vicente.botet_at_[hidden]
Date: 2009-10-21 03:59:08
Author: viboes
Date: 2009-10-21 03:59:07 EDT (Wed, 21 Oct 2009)
New Revision: 57030
URL: http://svn.boost.org/trac/boost/changeset/57030
Log:
TBoost.STM vbe: Fix bank example test
Text files modified:
sandbox/stm/branches/vbe/libs/stm/example/bank.cpp | 84 +++++++++------------------------------
1 files changed, 20 insertions(+), 64 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 2009-10-21 03:59:07 EDT (Wed, 21 Oct 2009)
@@ -69,23 +69,12 @@
struct teller {
teller(bank* b)
- : bank_(b){
- cerr << "teller this=" <<this<< endl;
- cerr << "ptr=" <<bank_<< endl;
- cerr << "size=" <<bank_->accounts.size()<< endl;
- }
- ~teller() {
- cerr << "~this=" <<this<< endl;
- }
+ : bank_(b){}
+ ~teller() {}
void operator()(){ //thread start
- cerr << "this=" <<this<< endl;
- cerr << "start"<< endl;
thread_initializer thi;
- cerr << "initialize_thread"<< endl;
- //while(!exit)
for(int i=10; i>0;--i)
{
- cerr << "c="<< i<<endl;
atomic(_) {
int amount=random() % 1000;
#if 0
@@ -93,22 +82,16 @@
#else
//rd_ptr<bank> rd_bank(_,bank_);
bank* rd_bank = bank_;
- //cerr << "rd_bank"<< endl;
#endif
- //cerr << "ptr=" <<rd_bank<< endl;
- //cerr << "size=" <<rd_bank->accounts.size()<< endl;
int acc1=random() % rd_bank->accounts.size();
int acc2=random() % rd_bank->accounts.size();
rd_bank->accounts[acc1]->Withdraw(amount);
rd_bank->accounts[acc2]->Deposit(amount+1);
- } catch(...) {
+ } end_atom
+ catch(...) {
cerr << "aborted"<< endl;
}
}
- cerr << "ptr=" <<bank_<< endl;
- cerr << "size=" <<bank_->accounts.size()<< endl;
- cerr << "balance=" <<bank_->overall_balance()<< endl;
- cerr << "end"<< endl;
}
bank* bank_;
static bool volatile exit;
@@ -118,43 +101,40 @@
void create_db(bank* b, int nr_of_accounts){
- //use_atomic(_)
+ //atomic(_)
{
for(int c=0;c<nr_of_accounts;++c){
- //cerr << "c=" <<c<< endl;
tx_ptr<BankAccount> acc(make_tx_ptr<BankAccount>(c));
- //cerr << "ptr=" <<acc.ptr_<< endl;
b->accounts.push_back(acc);
- //cerr << "size=" <<mybank->accounts.size()<< endl;
}
- }
+ } // end_atom
}
tx_ptr<BankAccount> a;
void account_withdraw_thr_basic() {
thread_initializer thi;
- use_atomic(_) {
+ atomic(_) {
a->Withdraw(10);
- }
+ } end_atom
}
void account_withdraw_thr() {
thread_initializer thi;
- use_atomic(_) {
+ atomic(_) {
make_wr_ptr(_,a)->Withdraw(10);
- }
+ } end_atom
}
void account_deposit_thr_basic() {
thread_initializer thi;
- use_atomic(_) {
+ atomic(_) {
a->Deposit(10);
- }
+ } end_atom
}
void account_deposit_thr() {
thread_initializer thi;
- use_atomic(_) {
+ atomic(_) {
make_wr_ptr(_,a)->Deposit(10);
- }
+ } end_atom
}
int test_account() {
@@ -168,7 +148,6 @@
th2.join();
th3.join();
th4.join();
- cerr << "ptr=" << a.ptr_ << " nb=" << a->Nb() << " bal=" << a->Balance() << endl;
int res = (a->Balance()==0?0:1);
//boost::stm::delete_ptr(a);
return res;
@@ -178,24 +157,22 @@
void vector_int_assign_basic() {
thread_initializer thi;
- use_atomic(_) {
+ atomic(_) {
(*v)[0]+=10;
- }
+ } end_atom
}
void vector_int_assign() {
thread_initializer thi;
- use_atomic(_) {
+ atomic(_) {
wr_ptr<std::vector<int> > wrv(_,v);
(*wrv)[0]+=10;
- }
+ } end_atom
}
int test_vector_int() {
v=make_tx_ptr<std::vector<int> >();
- cerr << "ptr=" << v.ptr_ << endl;
v->push_back(10);
- cerr << "ptr=" << v.ptr_ << " v[0]=" << v.ptr_->value[0] << endl;
thread th1(vector_int_assign);
thread th2(vector_int_assign_basic);
@@ -204,9 +181,6 @@
th1.join();
th2.join();
th3.join();
- cerr << "ptr=" << v.ptr_ << " v[0]=" << (*v)[0] << endl;
- //cerr << "ptr=" << v.ptr_ << " v[0]=" << v.ptr_->value[0] << endl;
- //cerr << "ptr=" << v.ptr_ << " v[0]=" << 0 << endl;
int res = ((*v)[0]==40?0:1);
//boost::stm::delete_ptr(v);
@@ -220,20 +194,11 @@
//int nr_of_threads=10;
int nr_of_accounts=200;
- cerr << __LINE__ << endl;
//cin >> wait;teller::exit=true;
bank abank;
bank* mybank=&abank;
create_db(mybank,nr_of_accounts);
- cerr << __LINE__ << endl;
//cin >> wait;teller::exit=true;
- //use_atomic(_)
- {
-
- //cerr << "size=" <<mybank.ptr_->value.accounts.size()<< endl;
- cerr << __LINE__ << " size=" <<mybank->accounts.size()<< endl;
- cerr << __LINE__ << " overall balance before: " << mybank->overall_balance() << endl;
- }
#if 0
mybank->accounts[0]->Withdraw(10);
@@ -242,27 +207,20 @@
#if 0
teller t(mybank);
t();
- //cerr << "size=" <<mybank->accounts.size()<< endl;
- //cerr << "overall balance before: " << mybank->overall_balance() << endl;
- cerr << __LINE__ << endl;
#endif
#if 1
teller t(mybank);
- cerr << "t=" <<&t<< endl;
thread* th1= new thread(boost::ref(t));
//thread* th2= new thread(teller(mybank));
cin >> wait;teller::exit=true;
- cerr << __LINE__ << endl;
th1->join();
delete th1;
//th2->join();
//delete th2;
- use_atomic(_) {
- cerr << "overall balance after: " << mybank->overall_balance() << endl;
- cerr << "balances after: " <<endl;
+ atomic(_) {
mybank->print_balance();
- }
+ } end_atom
#endif
#if 0
@@ -280,8 +238,6 @@
threads.pop_front();
}
- cerr << "overall balance after: " << mybank->overall_balance() << endl;
- cerr << "balances after: " << endl;
mybank->print_balance();
#endif
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