Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

may have fixed the race #3723

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions eo-runtime/src/main/java/org/eolang/AtRho.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,17 @@ public Attr copy(final Phi self) {

@Override
public Phi get() {
if (this.rho.get() == null) {
final Phi phi = this.rho.get();
if (phi == null) {
throw new ExUnset(
String.format("The \"%s\" attribute is not set", Attr.RHO)
);
}
return this.rho.get();
return phi;
}

@Override
public boolean put(final Phi phi) {
final boolean ret;
if (this.rho.get() == null) {
this.rho.set(phi);
ret = true;
} else {
ret = false;
}
return ret;
return this.rho.get() == null && this.rho.compareAndSet(null, phi);
}
}
4 changes: 1 addition & 3 deletions eo-runtime/src/main/java/org/eolang/AtVoid.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ public Phi get() {

@Override
public boolean put(final Phi phi) {
if (this.object.get() == null) {
this.object.set(phi);
} else {
if (this.object.get() != null || !this.object.compareAndSet(null, phi)) {
throw new ExReadOnly(
String.format(
"This void attribute \"%s\" is already set, can't reset",
Expand Down
Loading