Bounded Buffer Problem

24 views
Skip to first unread message

david

unread,
Jul 2, 2010, 6:17:58 AM7/2/10
to Deuce-STM
Hello,

We are making a presentation about STM and found the deuce framework.

We implemented a "transactional stack" (bounded buffer) as follows:

public class MyStack {
private final Stack<Integer> stack;
private int size;

public MyStack(int size) {
this.size = size;
stack = new Stack<Integer>();
};

@Atomic
public void put(int item) {
if (stack.size() == size) {
throw new TransactionException();
}
assert (stack.size() < size):"stack overflow";
stack.push(item);
};

@Atomic
public int get() {
if (stack.isEmpty()) {
throw new TransactionException();
}
assert (stack.size() > 0):"stack empty";
return stack.pop();
}
}


Running the following Test Case we get AssertionErrors (stack overflow
and stack empty). Our implementation seems correct, is there something
we missed?

We assumed "throw new TransactionException();" restarts the
corresponding method.

public class StackTest {

final static MyStack buffer = new MyStack(1);

public static void main(String[] args) {
final Random r = new Random();
for (int i = 0; i < 1; i++) {
new Thread() {
public void run() {
while (true) {
buffer.get();
}
}
}.start();
}
for (int i = 0; i < 1; i++) {
new Thread() {
public void run() {
while (true) {
buffer.put(r.nextInt());
}
}
}.start();
}
}

}


Thank you in advance.

Greetings

David

Guy Korland

unread,
Jul 3, 2010, 5:07:16 AM7/3/10
to deuce-stm
How do you run DeuceSTM?
Are you using javaagent?
If so then the problem is probably because the rt.jar (the jdk classes) are can't be instrumented online. For that you can use the offline mode to instrument the JDK classes. To read more about it see: http://www.deucestm.org/documentation/getting-started

Also notice that since java.util.Stack extends java.util.Vector all the methods are synchronized which means you probably won't see any  scalability. I would recommend using your own code for the Stack ( you can even just copy the code from the JDK). 

Regards,
Guy Korland



--
You received this message because you are subscribed to the Google Groups "Deuce-STM" group.
To post to this group, send email to deuc...@googlegroups.com.
To unsubscribe from this group, send email to deuce-stm+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/deuce-stm?hl=en.


Reply all
Reply to author
Forward
0 new messages