@Override
    public void lock(int myId) {
    	while(true){
    		flag[myId]=true;
    		last=myId;
    		if (open_id!=-1){ //door close
    			flag[myId]=false;
    			while (open_id!=-1);
    			continue;
    		}
    		else{
    			open_id=myId; //I close the door
    			if(last==myId)
    				return; //Down
    			else{
    				flag[myId]=false;
    				boolean op_flag=true;
    				while(op_flag==true){
    					op_flag=false;
    					for (int i=0; i<Thread_num; i++){
    						if(flag[i]==true)
    							op_flag=true;
    					}
    				}
    				if(open_id==myId)
    					return;
    				else{
    					while(open_id!=-1);
    					continue;
    				}
    			}
    		}
    	}
    }