Skip to content

Commit

Permalink
fix(Behavior): Use atomic lookup instead of synchronized in `restar…
Browse files Browse the repository at this point in the history
…t()`
  • Loading branch information
ettersi committed Dec 19, 2024
1 parent 166e74c commit 592cae5
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/main/java/org/arl/fjage/Behavior.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,13 @@ public void run() {
*
* @see #block()
*/
public synchronized void restart() {
public void restart() {
blocked = false;
if (agent != null) agent.wake();
// Use local variable to ensure that the `!= null` and `.wake()` run on the
// same value. Don't use `synchronized` block as that may deadlock with the
// `agent` lock required for `wake()`.
Agent tmp = agent;
if (tmp != null) tmp.wake();
}

/**
Expand Down Expand Up @@ -249,4 +253,3 @@ synchronized void setOwner(Agent agent) {
}

}

0 comments on commit 592cae5

Please sign in to comment.