public void stop() throws InterruptedException {
		if (stopCalled) {
			return;
		}
		stopCalled = true;
//		System.out.println("stop ");
		for (int i = 0; i < threadsCount; i++) {
			GridWorker x = threads[i];
			x.setIsRunning(false);		
		}
		

		
		while(true) {
			boolean allStopped = true;
			for (int i = 0; i < threadsCount; i++) {
				if (!threads[i].getIsFinished()) {
					// System.out.println(i);
					allStopped = false;
					break;
				}
			}
			
			if (allStopped) {
				break;
			} else {
				synchronized (getStack()) {
					stack.clear();
					stack.notify();			
				}						
				synchronized (threadStates) {					
					threadStates.wait();
				}
			}
		}
		
		
		
//		synchronized (threadStates) {
//			threadStates.notify();
//		}		
	}