(New page: atomic operation once it starts, it will finish without being interrupted in database, this is called transaction processing (concurrency control) ATM1 ATM2 balance=1000 ...)
 
 
Line 1: Line 1:
atomic operation
+
<p>atomic operation<br /> once it starts, it will finish without being interrupted<br /> in database, this is called transaction processing (concurrency control)
  once it starts, it will finish without being interrupted
+
</p><p><br />
  in database, this is called transaction processing (concurrency control)
+
</p><p>ATM1 ATM2<br />balance=1000 <br />1 read balance 5 read balance<br />2 balance-=100 6 balance-=100<br />3 give cash 7 give cash<br />4 update balance 8 update balance<br /> write to db write to db
 
+
</p><p>1<br />1000<br /> 5<br /> 1000<br />2<br />900
ATM1           ATM2
+
</p><p>3<br />get $
balance=1000  
+
</p><p>6<br /> 900<br /> <br /> 7<br /> get $<br />4<br />db=900<br /> <br /> 8<br /> 900
1 read balance   5 read balance
+
</p><p>class MyThread extends Thread<br />{<br /> private int[] a;<br /> private int[] b;<br /> private int[] c;<br /> private int first;<br /> private int last;<br /> public MyThread (int[] x, int[] y, int[] z, int f int l)<br /> {<br /> a=x;<br /> b=y;<br /> c=z;<br /> first=f;<br /> last=l;<br /> }<br /> public void run()<br /> {<br /> for (int i=first;i&lt;=last;i++)<br /> {<br /> c[i]=a[i]+b[i];<br /> }<br /> }<br />}
2 balance-=100   6 balance-=100
+
</p><p>int[] a=new int[100];<br />int[] b=new int[100];<br />int[] c=new int[100];<br />initialize a,b,c<br />MyThread t1=new MyThread(a,b,c,0,24);<br />MyThread t2=new MyThread(a,b,c,25,49);<br />MyThread t3=new MyThread(a,b,c,50,74);<br />MyThread t4=new MyThread(a,b,c,75,99);<br />t1.start();<br />t2.start();<br />t3.start();<br />t4.start();<br />t1.join();<br />t2.join();<br />t3.join();<br />t4.join();
3 give cash     7 give cash
+
</p><p>1. do they share data?<br /> false
4 update balance 8 update balance
+
</p><p>SIMD S=Single<br />MIMD M=Multiple<br />SISD I=Instruction<br />MISD D=Data<br />
  write to db     write to db
+
</p><p><br />
 
+
}
1
+
</p><p>int[] a=new int[100]; int[] b=new int[100]; int[] c=new int[100]; initialize a,b,c MyThread t1=new MyThread(a,b,c,0,24); MyThread t2=new MyThread(a,b,c,25,49); MyThread t3=new MyThread(a,b,c,50,74); MyThread t4=new MyThread(a,b,c,75,99); t1.start(); t2.start(); t3.start(); t4.start(); t1.join(); t2.join(); t3.join(); t4.join();
1000
+
</p><p>1. do they share data?  
      5
+
</p>
      1000
+
<pre class="_fck_mw_lspace">  false
2
+
</pre>
900
+
<p>SIMD S=Single MIMD M=Multiple SISD I=Instruction MISD D=Data
 
+
</p>
3
+
get $
+
 
+
      6
+
      900
+
     
+
      7
+
      get $
+
4
+
db=900
+
+
      8
+
      900
+
 
+
class MyThread extends Thread
+
{
+
  private int[] a;
+
  private int[] b;
+
  private int[] c;
+
  private int first;
+
  private int last;
+
  public MyThread (int[] x, int[] y, int[] z, int f int l)
+
  {
+
    a=x;
+
    b=y;
+
    c=z;
+
    first=f;
+
    last=l;
+
  }
+
  public void run()
+
  {
+
    for (int i=first;i<=last;i++)
+
    {
+
      c[i]=a[i]+b[i];
+
    }
+
  }
+
}
+
 
+
int[] a=new int[100];
+
int[] b=new int[100];
+
int[] c=new int[100];
+
initialize a,b,c
+
MyThread t1=new MyThread(a,b,c,0,24);
+
MyThread t2=new MyThread(a,b,c,25,49);
+
MyThread t3=new MyThread(a,b,c,50,74);
+
MyThread t4=new MyThread(a,b,c,75,99);
+
t1.start();
+
t2.start();
+
t3.start();
+
t4.start();
+
t1.join();
+
t2.join();
+
t3.join();
+
t4.join();
+
 
+
1. do they share data?
+
    false
+
 
+
SIMD   S=Single
+
MIMD   M=Multiple
+
SISD   I=Instruction
+
MISD   D=Data
+

Latest revision as of 16:03, 3 November 2010

atomic operation
once it starts, it will finish without being interrupted
in database, this is called transaction processing (concurrency control)


ATM1 ATM2
balance=1000
1 read balance 5 read balance
2 balance-=100 6 balance-=100
3 give cash 7 give cash
4 update balance 8 update balance
write to db write to db

1
1000
5
1000
2
900

3
get $

6
900

7
get $
4
db=900

8
900

class MyThread extends Thread
{
private int[] a;
private int[] b;
private int[] c;
private int first;
private int last;
public MyThread (int[] x, int[] y, int[] z, int f int l)
{
a=x;
b=y;
c=z;
first=f;
last=l;
}
public void run()
{
for (int i=first;i<=last;i++)
{
c[i]=a[i]+b[i];
}
}
}

int[] a=new int[100];
int[] b=new int[100];
int[] c=new int[100];
initialize a,b,c
MyThread t1=new MyThread(a,b,c,0,24);
MyThread t2=new MyThread(a,b,c,25,49);
MyThread t3=new MyThread(a,b,c,50,74);
MyThread t4=new MyThread(a,b,c,75,99);
t1.start();
t2.start();
t3.start();
t4.start();
t1.join();
t2.join();
t3.join();
t4.join();

1. do they share data?
false

SIMD S=Single
MIMD M=Multiple
SISD I=Instruction
MISD D=Data


}

int[] a=new int[100]; int[] b=new int[100]; int[] c=new int[100]; initialize a,b,c MyThread t1=new MyThread(a,b,c,0,24); MyThread t2=new MyThread(a,b,c,25,49); MyThread t3=new MyThread(a,b,c,50,74); MyThread t4=new MyThread(a,b,c,75,99); t1.start(); t2.start(); t3.start(); t4.start(); t1.join(); t2.join(); t3.join(); t4.join();

1. do they share data?

   false

SIMD S=Single MIMD M=Multiple SISD I=Instruction MISD D=Data

Alumni Liaison

Ph.D. 2007, working on developing cool imaging technologies for digital cameras, camera phones, and video surveillance cameras.

Buyue Zhang