|
65 | 65 | * and <em>shared</em> arenas. |
66 | 66 | * <p> |
67 | 67 | * Confined arenas, support strong thread-confinement guarantees. Upon creation, they are assigned an |
68 | | - * {@linkplain #isOwnedBy(Thread) owner thread}, typically the thread which initiated the creation operation. |
| 68 | + * {@linkplain #isCloseableBy(Thread) owner thread}, typically the thread which initiated the creation operation. |
69 | 69 | * The segments created by a confined arena can only be {@linkplain MemorySession#isAccessibleBy(Thread) accessed} |
70 | 70 | * by the thread that created the arena. Moreover, any attempt to close the confined arena from a thread other than the owner thread will |
71 | 71 | * fail with {@link WrongThreadException}. |
72 | 72 | * <p> |
73 | 73 | * Shared memory sessions, on the other hand, have no owner thread. The segments created by a shared arena |
74 | 74 | * can be {@linkplain MemorySession#isAccessibleBy(Thread) accessed} by multiple threads. This might be useful when |
75 | 75 | * multiple threads need to access the same memory segment concurrently (e.g. in the case of parallel processing). |
76 | | - * Moreover, a shared arena can be closed by any thread. |
| 76 | + * Moreover, a shared arena {@linkplain #isCloseableBy(Thread) can be closed} by any thread. |
77 | 77 | * |
78 | 78 | * @since 20 |
79 | 79 | */ |
@@ -128,7 +128,7 @@ default MemorySegment allocate(long byteSize, long byteAlignment) { |
128 | 128 | * {@return {@code true} if the provided thread can close this arena} |
129 | 129 | * @param thread the thread to be tested. |
130 | 130 | */ |
131 | | - boolean isOwnedBy(Thread thread); |
| 131 | + boolean isCloseableBy(Thread thread); |
132 | 132 |
|
133 | 133 | /** |
134 | 134 | * Creates a new confined arena. |
@@ -159,9 +159,10 @@ public void close() { |
159 | 159 | } |
160 | 160 |
|
161 | 161 | @Override |
162 | | - public boolean isOwnedBy(Thread thread) { |
| 162 | + public boolean isCloseableBy(Thread thread) { |
163 | 163 | Objects.requireNonNull(thread); |
164 | | - return sessionImpl.ownerThread() == thread; |
| 164 | + return sessionImpl.ownerThread() == null || // shared |
| 165 | + sessionImpl.ownerThread() == thread; |
165 | 166 | } |
166 | 167 | }; |
167 | 168 | } |
|
0 commit comments