public void waitUntil(boolean v) throws InterruptedException{
	
		 // wait only if the value is not already v
		 if (value != v){

			// set the until value (field) to v
			until_value = v;

			// mark waiting
			waiting = true;
			
			// recheck the condition
			if (value != v){
				// wait while the wait flag is true (ie the value differs from the conditional value)
				while ( waiting ){ 
					// wait is synchronized on this
					synchronized(this){
						g_syncWaits++;
						
					    if (waitTerminated){ waiting = false; throw new InterruptedException(); }
						
						// recheck the wait flag
						if (waiting){
					
							// wait on this
							try{ this.wait(); } 
							catch(InterruptedException interrupted){ waiting = false; throw interrupted; }
							// catch(Throwable ignored){} // might be better handled in production quality
						}
						
					    if (waitTerminated){ waiting = false; throw new InterruptedException(); }
					}
				}
			}
			// the condition so far became true
			else{
				// unset the wait flag
				waiting = false;				
			}
		}
	}