realized? on a delay blocks for result

Description

Per https://ask.clojure.org/index.php/10004/calling-realized-delay-currently-executing-blocks-caller ...

`realized?` on a delay that is in the process of being realized blocks rather than just returning false:

Cause: Delay.isRealized() is synchronized against the same (this) lock that is used when forcing the delay, so calling `realized?` on it will effectively block until the result is done, then return true.

Approach: the fn field being checked is volatile - it's safe to just race with the realization and check if it's set yet by removing synchronized on the isRealized() method.

Patch: clj-2600.patch

Environment

None

Activity

Show:
Michael Fogus
January 6, 2021, 1:42 PM

Reasoned through the change, applied, tested, ran through in REPL.

Alex Miller
January 5, 2021, 10:53 PM
Your pinned fields
Click on the next to a field label to start pinning.

Assignee

Unassigned

Reporter

Alex Miller

Approval

Screened

Patch

Code

Priority

Major

Affects versions

Fix versions