protected synchronized void lock(int i){
			if (locked){
				try{
					lockRequest = true;					
					switch(i){
						case 0: g_wait0 = true; break;
						case 1: g_wait1 = true; break;
					}
					// System.out.println(this);
					while (locked){ 
						try{ this.wait(); }
						catch(Throwable th){ throw new RuntimeException(th); }
					}
				}
				finally{
					lockRequest = false;
					switch(i){
						case 0: g_wait0 = false; break;
						case 1: g_wait1 = false; break;
					}
				}
			}
			
			locked = true;
		}