13 #include "allocator.h"
18 #include "transaction.h"
20 #include "xthread.cpp"
26 #define TRANSACTIONAL_STRICT_assert
40 Payload() : Transactional::Node<
LongNode>::Payload(), m_x(0) {}
41 Payload(
const Payload &x) : Transactional::Node<
LongNode>::Payload(x), m_x(x.m_x) {
47 operator long()
const {
return m_x;}
48 Payload &operator=(
const long &x) {
53 Payload &operator+=(
const long &x) {
66 #define trans(node) for(Transaction \
67 implicit_tr(node, false); !implicit_tr.isModified() || !implicit_tr.commitOrNext(); ) implicit_tr[node]
70 typename std::enable_if<std::is_base_of<LongNode, T>::value,
76 #include "transaction_impl.h"
79 shared_ptr<LongNode> gn1, gn2, gn3, gn4;
81 #define NUM_SLOW_THREADS 2
85 start_routine(
int th_no) {
90 if(th_no < NUM_SLOW_THREADS) {
96 shared_ptr<LongNode> p1(LongNode::create<LongNode>());
97 shared_ptr<LongNode> p2(LongNode::create<LongNode>());
98 for(
int i = 0; i < lps; i++) {
109 tr1[gn1] = ctr1[gn1] + 1;
110 tr1[gn3] = ctr1[gn3] + 1;
112 tr1[gn1] = str1[gn1] - 1;
113 tr1[gn2] = str1[gn2] + 1;
115 tr1[p2] = str1[p2] + 1;
117 if(wait) msecsleep(10);
122 tr1[gn4] = tr1[gn4] + 1;
123 tr1[gn4] = tr1[gn4] - 1;
124 if(wait) msecsleep(30);
130 tr1[gn2] = tr1[gn2] - 1;
131 tr1[gn3] = str1[gn3] - 1;
133 tr1[p2] = str1[p2] - 1;
135 if(wait) msecsleep(60);
146 printf(
"Error! P2=%ld\n", y);
150 printf(
"finish no=%d\n", th_no);
151 if(th_no < NUM_SLOW_THREADS) {
158 main(
int argc,
char **argv)
160 for(
int k = 0; k < 1; k++) {
161 gn1.reset(LongNode::create<LongNode>());
162 gn2.reset(LongNode::create<LongNode>());
163 gn3.reset(LongNode::create<LongNode>());
164 gn4.reset(LongNode::create<LongNode>());
172 long x = shot1[*gn3];
173 printf(
"Gn3:%ld\n", x);
177 printf(
"Gn3:%ld\n", x);
180 shared_ptr<LongNode> p1(LongNode::create<LongNode>());
188 shared_ptr<LongNode> p2(LongNode::create<LongNode>());
189 shared_ptr<LongNode> p21(LongNode::create<LongNode>());
190 shared_ptr<LongNode> p22(LongNode::create<LongNode>());
191 shared_ptr<LongNode> p211(LongNode::create<LongNode>());
218 tr1[gn1] = ctr1[gn1] + 1;
219 tr1[gn3] = ctr1[gn3] + 1;
221 tr1[gn1] = str1[gn1] - 1;
222 tr1[gn3] = str1[gn3] - 1;
228 std::thread threads[NUM_THREADS];
230 for(
int i = 0; i < NUM_THREADS; i++) {
231 std::thread th( &start_routine, i);
240 for(
int i = 0; i < NUM_THREADS; i++) {
245 if(***gn1 || ***gn2 || ***gn3 || ***gn4) {
247 printf(
"Gn1:%ld\n", (
long)***gn1);
248 printf(
"Gn2:%ld\n", (
long)***gn2);
249 printf(
"Gn3:%ld\n", (
long)***gn3);
250 printf(
"Gn4:%ld\n", (
long)***gn4);
265 printf(
"failed total=%ld\n", (
long)total);
269 printf(
"succeeded\n");