package visibility;

/**
 * The same as Spinner, except that shutdown_ is volatile.
 */
public class VolatileSpinner implements Runnable {

	private volatile boolean shutdown_;
	private long spins_;

	public VolatileSpinner () {
		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;
	}

}
