All Downloads are FREE. Search and download functionalities are using the official Maven repository.

blah.concurrency.second.Data Maven / Gradle / Ivy

There is a newer version: 2.1.0
Show newest version
package blah.concurrency.second;


public class Data {

	final FieldReference wroteField = FieldReference.wrap( this, "wrote" );
//	final Locker readLocker = new Locker();
//	final Locker writeLocker = new Locker();

	volatile T value;
	volatile int wrote = 0;

	public T get() {
		while( true )
			if ( wroteField.compareAndSet( 1, 0 ) )
				return currentValue();
	}

	public T set(final T data) {
		while( true )
			if ( wroteField.compareAndSet( 0, 1 ) )
				return this.value = data;
	}

	T currentValue() {
		return value;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy