package edu.bjtu.os;
public class Actiona implements Runnable {
@SuppressWarnings("deprecation")
@Override
public void run() {
// TODO Auto-generated method stub
while(Hw1.index<999){
if(Hw1.ME==-1){
//Hw1.ME=-1;
//Hw1.bThread.resume();
try {
synchronized (Hw1.Actb) {
Hw1.Actb.notify();
Thread.currentThread().sleep(100);
}
//wait();
} catch (Exception e) {
try {
Thread.currentThread().sleep(100);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// TODO Auto-generated catch block
//e.printStackTrace();
}
}
else{
Hw1.ME=1;
try {
System.out.println("a sleep");
synchronized (Hw1.Acta) {
Hw1.Acta.wait();
}
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("a wake");
if(Hw1.ME==1){
if(Hw1.index==999){
Hw1.endIndex=999;
// Hw1.bThread.notify();
// return;
}
else{
int m=Hw1.index+(int)(Math.random()*(1000-Hw1.index));
if(m+Hw1.index>999){
m=999;
}
Hw1.endIndex=m;
}
}
//Hw1.bThread.notify();
/////v
Hw1.ME=-1;
}
}
}
}