How Deuce is handling this conflict

33 views
Skip to first unread message

Tharun Tej

unread,
Oct 31, 2011, 7:41:28 PM10/31/11
to Deuce-STM, thar...@gmail.com
Hi,

I have been running one of the program using Deuce.
The program is as follows.


/
*****************************************************************************************************************************************************************************************************************/


import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Logger;

import org.deuce.Atomic;


class Account
{
int checking, savings;
public Account(int i ,int j)
{
checking = i; savings = j;
}
@Atomic
void transfer(int n)
{
System.out.println("Checkings before Transfer:"+checking);
checking += n;
System.out.println("Checkings After Transfer:"+checking);
System.out.println("Counter before first call
is :"+Global.opCounter);
Global.inc();
System.out.println("Counter after first call
is :"+Global.opCounter);
System.out.println("Savings before :"+savings);
savings -= n;
System.out.println("Savings after : "+savings);
System.out.println("Counter before Second call
is :"+Global.opCounter);
Global.inc();
System.out.println("Counter after Second call
is :"+Global.opCounter);
}
}

class Global
{
static int opCounter = 0;
@Atomic
static void inc()
{
opCounter++;
}
}
public class Test
{
public static void main(String args[]) throws SecurityException,
IOException
{
final Account x = new Account(4,7);
Thread T1 = new Thread()
{
public void run()
{
x.transfer(2);
}
};

Thread T2 = new Thread()
{
public void run()
{
Global.inc();
System.out.println("Thread 2 incremented Counter::"+
Global.opCounter);
}
};
T1.setName(" Transaction");
T1.start();
T2.setName(" Opcounter");
T2.start();
System.out.println("Finally:"+Global.opCounter);

}
}


/
****************************************************************************************************************************************************************************************************************/





Now when I run the program it should ensure that it runs atomically,
means when Thread 1 is performing some operation it should not be
disturbed by any of the other operations.
For example in the Thread 1 we are transferring the money from savings
account to current account and incrementing the global opcounter
simultaneously in the transfer method.

There is other thread called T2 which call the incrementing opcounter
method.

The Question is : when the Thread 1 is performing operations until if
finishes the operations T2 should not enter. Means the flow of the
execution should be T1, T2 or T2, T1 but not T1,T2,T1.

Here are the various outputs (Schedules )that I got.
First is the correct output schedule.

C:\Eclipse3.5 Workspace\AtomicSetSerializabilit_Deuce\src>java -
javaagent:deuceAgent-1.3.0.jar Test
Finally:0
Thread 2 incremented Counter::1
Checkings before Transfer:4
Checkings After Transfer:6
Counter before first call is :1
Counter after first call is :2
Savings before :7
Savings after : 5
Counter before Second call is :2
Counter after Second call is :3

C:\Eclipse3.5 Workspace\AtomicSetSerializabilit_Deuce\src>


/
************************************************************************************************************************************************************************/


CONFLICT Schedule::


C:\Eclipse3.5 Workspace\AtomicSetSerializabilit_Deuce\src>java -
javaagent:deuceAgent-1.3.0.jar Test
Finally:0
Checkings before Transfer:4
Checkings After Transfer:6
Counter before first call is :1
Thread 2 incremented Counter::1
-----------------------------------------------------> Why is this
coming here? How are you resolving this.
Counter after first call is :2
Savings before :7
Savings after : 5
Counter before Second call is :2
Counter after Second call is :3


/
************************************************************************************************************************************************************************************/



So in the above conflict schedule T2 is coming in the middle of T1. so
how are you handling this . This should not be the case.

If you find any difficulties in understanding the problem please let
me know.
Thank you.








Guy Korland

unread,
Oct 31, 2011, 8:58:33 PM10/31/11
to deuc...@googlegroups.com, thar...@gmail.com
Hi,

You can't relay on the System.out to debug the transactions.
Since this code is part of the JDK it doesn't instrumented by default and therefor ignored by the transactions.

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.


Tharun Tej

unread,
Oct 31, 2011, 10:35:56 PM10/31/11
to Deuce-STM
Can you suggest me how to exactly trace the flow of transactions?
I want to trace the flow.

Guy Korland

unread,
Oct 31, 2011, 11:10:31 PM10/31/11
to deuc...@googlegroups.com
what is the reason?
debug or you need this information?


Sent from Orange email services

Tharun Tej

unread,
Oct 31, 2011, 11:14:19 PM10/31/11
to Deuce-STM
I wanted to trace the flow and check that conflict schedule is not
coming.
So any better way to identify it? And wanted to find how deuce is
resolving those conflict schedules.

On Oct 31, 9:10 pm, Guy Korland <gkorl...@gmail.com> wrote:
> what is the reason?
> debug or you need this information?
>
> Sent from Orange email services
>

Guy Korland

unread,
Nov 3, 2011, 4:15:12 PM11/3/11
to deuc...@googlegroups.com
You gather all this information by extending the relevant STM algorithm Context.

Guy
Reply all
Reply to author
Forward
0 new messages