package visibility;

/**
 * Spins until shut down. shutdown_ is NOT volatile, so the spinning thread
 * may never see the change.
 */
public class Spinner implements Runnable {

	private boolean shutdown_;
	private long spins_;

	public Spinner () {
		shutdown_ = false;
		spins_ = 0;
	}

	@Override
	public void run () {
		System.out.println("["+getClass().getName()+"] spinner starting");
		for ( ; !shutdown_ ; ) {
			spins_++;
		}
		System.out.println("["+getClass().getName()+"] spinner saw shutdown_ and finished");
	}

	public void shutdown () {
		shutdown_ = true;
	}

}
