Commit 02bc03d
authored
fix(ZBytes): publish the lazy byte cache safely (#517)
The lazy materialization in ZBytes is double-checked locking: the fast path
reads `eager` outside the monitor while the slow path writes it under it.
Without volatile, a reader observing the non-null reference has no
happens-before edge to the copy that filled the array.
Mark `eager` volatile. It moves out of the primary constructor because
@volatile targets fields. The synchronized slow path stays: it is what
guarantees exactly one thread copies out of and closes the native handle.
`handle` stays non-volatile — it is only touched inside the monitor.
Closes #5161 parent 102fb8c commit 02bc03d
1 file changed
Lines changed: 10 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
55 | 64 | | |
56 | 65 | | |
57 | 66 | | |
| |||
0 commit comments