|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r62190 - sandbox/stm/libs/stm/test
From: justin_at_[hidden]
Date: 2010-05-25 00:48:08
Author: jgottschlich
Date: 2010-05-25 00:48:07 EDT (Tue, 25 May 2010)
New Revision: 62190
URL: http://svn.boost.org/trac/boost/changeset/62190
Log:
added tests for embedded and buffered delete.
Added:
sandbox/stm/libs/stm/test/testBufferedDelete.cpp (contents, props changed)
sandbox/stm/libs/stm/test/testBufferedDelete.h (contents, props changed)
sandbox/stm/libs/stm/test/testEmbedded.cpp (contents, props changed)
sandbox/stm/libs/stm/test/testEmbedded.h (contents, props changed)
Added: sandbox/stm/libs/stm/test/testBufferedDelete.cpp
==============================================================================
--- (empty file)
+++ sandbox/stm/libs/stm/test/testBufferedDelete.cpp 2010-05-25 00:48:07 EDT (Tue, 25 May 2010)
@@ -0,0 +1,100 @@
+
+//#include <boost/thread.hpp>
+//#include <boost/random.hpp>
+#include <boost/stm.hpp>
+#include <cstdlib>
+#include <ctime>
+#include "testatom.h"
+#include "main.h"
+
+namespace stm = boost::stm;
+
+
+class Simple : public boost::stm::transaction_object< Simple >
+{
+public:
+
+ int val_;
+};
+
+Simple *instance = new Simple;
+
+using namespace stm;
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+void* BufferedDeleteEntry(void* threadId)
+{
+ stm::transaction::initialize_thread();
+ int start = *(int*)threadId;
+
+ for (int i = 0; i < 10000; ++i)
+ {
+ atomic(tx) {
+ Simple const *ref = &tx.read(*instance);
+
+ for (int j = 0; j < 50; ++j)
+ {
+ cout << i << ", " << j << ":\t" << ref->val_ << endl;
+ }
+ } end_atom
+ }
+
+ finishThread(start);
+
+ if (*(int*)threadId != kMainThreadId)
+ {
+ transaction::terminate_thread();
+ pthread_exit(threadId);
+ }
+
+ return NULL;
+}
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+int testBufferedDelete()
+{
+ stm::transaction::initialize();
+ stm::transaction::initialize_thread();
+ srand(time(NULL));
+
+ stm::transaction::do_deferred_updating();
+
+ instance->val_ = 0;
+
+ pthread_t *threads = new pthread_t[kMaxThreads];
+ int *threadId = new int[kMaxThreads];
+
+ //--------------------------------------------------------------------------
+ // Reset barrier variables before creating any threads. Otherwise, it is
+ // possible for the first thread
+ //--------------------------------------------------------------------------
+ threadsFinished.value() = 0;
+ threadsStarted.value() = 0;
+ startTimer = nMain::kStartingTime;
+ endTimer = 0;
+
+ for (int j = 0; j < kMaxThreads - 1; ++j)
+ {
+ threadId[j] = j;
+ pthread_create(&threads[j], NULL, BufferedDeleteEntry, (void *)&threadId[j]);
+ }
+
+ int mainThreadId = kMaxThreads-1;
+ kMainThreadId = kMaxThreads-1;
+
+ atomic(tx)
+ {
+ cout << "in delete" << endl;
+ tx.delete_memory(*instance);
+ } end_atom
+
+ while (true)
+ {
+ if (threadsFinished.value() == kMaxThreads) break;
+ SLEEP(10);
+ }
+
+ return 0;
+}
Added: sandbox/stm/libs/stm/test/testBufferedDelete.h
==============================================================================
--- (empty file)
+++ sandbox/stm/libs/stm/test/testBufferedDelete.h 2010-05-25 00:48:07 EDT (Tue, 25 May 2010)
@@ -0,0 +1,10 @@
+#ifndef TEST_BUFFERED_DELETE_H
+#define TEST_BUFFERED_DELETE_H
+
+
+int testBufferedDelete();
+
+
+#endif // TEST_BUFFERED_DELETE_H
+
+
Added: sandbox/stm/libs/stm/test/testEmbedded.cpp
==============================================================================
--- (empty file)
+++ sandbox/stm/libs/stm/test/testEmbedded.cpp 2010-05-25 00:48:07 EDT (Tue, 25 May 2010)
@@ -0,0 +1,147 @@
+
+//#include <boost/thread.hpp>
+//#include <boost/random.hpp>
+#include <boost/stm.hpp>
+#include <cstdlib>
+#include <ctime>
+#include "testEmbedded.h"
+#include "main.h"
+
+namespace stm = boost::stm;
+
+using namespace stm;
+
+class C1 : public transaction_object<C1>
+{
+public:
+ int i;
+};
+
+class C2 : public transaction_object<C2>
+{
+public:
+ int i;
+};
+
+class E : public transaction_object<E>
+{
+public:
+ E() { c1.i = -1; c2.i = -1; i = -1; }
+
+ int i;
+ C1 c1;
+ C2 c2;
+};
+
+E e;
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+void* embedded1(void* threadId)
+{
+ stm::transaction::initialize_thread();
+
+ atomic(t)
+ {
+ t.w(e).i = 0;
+
+ //------------------------------------------------------
+ // lines of code that would be generated by:
+ // boost::stm::bind(this, c1);
+ // boost::stm::bind(this, c2);
+ //------------------------------------------------------
+
+ t.w(e.c1);
+ t.w(e.c2);
+
+ atomic(t)
+ {
+
+ t.w(e.c2).i = 5;
+ } end_atom
+ } end_atom
+
+ return NULL;
+}
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+void* embedded2(void* threadId)
+{
+ stm::transaction::initialize_thread();
+
+ atomic(t)
+ {
+ t.w(e.c2).i = 5;
+
+ atomic(t)
+ {
+
+ t.w(e).i = 0;
+
+ //------------------------------------------------------
+ // lines of code that would be generated by:
+ // boost::stm::bind(this, c1);
+ // boost::stm::bind(this, c2);
+ //------------------------------------------------------
+
+ t.w(e.c1);
+ t.w(e.c2);
+
+ } end_atom
+ } end_atom
+
+ return NULL;
+}
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+int testEmbedded()
+{
+ std::cout << "-----------------------------------------------" << std::endl;
+ std::cout << "Processing embedded1: " << std::endl << std::endl;
+ std::cout << "Initial value of e.i: " << e.i << endl;
+ std::cout << "Initial value of e.c1.i: " << e.c1.i << endl;
+ std::cout << "Initial value of e.c2.i: " << e.c2.i << endl;
+
+ stm::transaction::initialize();
+ stm::transaction::initialize_thread();
+ srand(time(NULL));
+
+ int mainThreadId = kMaxThreads-1;
+
+ embedded1((void*)&mainThreadId);
+
+ std::cout << "-----------------------------------------------" << std::endl;
+ std::cout << "Ending processing." << std::endl;
+ std::cout << "Ending value of e.i: " << e.i << endl;
+ std::cout << "Ending value of e.c1.i: " << e.c1.i << endl;
+ std::cout << "Ending value of e.c2.i: " << e.c2.i << endl;
+
+
+ std::cout << "-----------------------------------------------" << std::endl;
+ std::cout << "Resetting e" << std::endl;
+ std::cout << "-----------------------------------------------" << std::endl;
+
+ e.i = -1;
+ e.c1.i = -1;
+ e.c2.i = -1;
+
+ std::cout << "-----------------------------------------------" << std::endl;
+ std::cout << "Processing embedded2: " << std::endl << std::endl;
+ std::cout << "Initial value of e.i: " << e.i << endl;
+ std::cout << "Initial value of e.c1.i: " << e.c1.i << endl;
+ std::cout << "Initial value of e.c2.i: " << e.c2.i << endl;
+
+ embedded1((void*)&mainThreadId);
+
+ std::cout << "-----------------------------------------------" << std::endl;
+ std::cout << "Ending processing." << std::endl;
+ std::cout << "Ending value of e.i: " << e.i << endl;
+ std::cout << "Ending value of e.c1.i: " << e.c1.i << endl;
+ std::cout << "Ending value of e.c2.i: " << e.c2.i << endl;
+
+
+ return 0;
+}
+
Added: sandbox/stm/libs/stm/test/testEmbedded.h
==============================================================================
--- (empty file)
+++ sandbox/stm/libs/stm/test/testEmbedded.h 2010-05-25 00:48:07 EDT (Tue, 25 May 2010)
@@ -0,0 +1,6 @@
+#ifndef TEST_EMBEDDED_H
+#define TEST_EMBEDDED_H
+
+int testEmbedded();
+
+#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