Skip to content

Commit ee6dc14

Browse files
committedNov 12, 2024
Merge loom into fibers
2 parents a1fb337 + 1fc7bfb commit ee6dc14

File tree

2 files changed

+21
-36
lines changed

2 files changed

+21
-36
lines changed
 

‎src/java.base/share/classes/java/util/concurrent/StructuredTaskScope.java

+20-22
Original file line numberDiff line numberDiff line change
@@ -917,9 +917,10 @@ static <T> StructuredTaskScope<T, Void> open() {
917917
}
918918

919919
/**
920-
* Starts a new thread in this scope to execute a value-returning task, thus creating
921-
* a <em>subtask</em>. The value-returning task is provided to this method as a
922-
* {@link Callable}, the thread executes its {@link Callable#call() call} method.
920+
* Fork a subtask by starting a new thread in this scope to execute a value-returning
921+
* method. The new thread executes the subtask concurrently with the current thread.
922+
* The parameter to this method is a {@link Callable}, the new thread executes its
923+
* {@link Callable#call() call()} method.
923924
*
924925
* <p> This method first creates a {@link Subtask Subtask} object to represent the
925926
* <em>forked subtask</em>. It invokes the joiner's {@link Joiner#onFork(Subtask) onFork}
@@ -969,12 +970,13 @@ static <T> StructuredTaskScope<T, Void> open() {
969970
<U extends T> Subtask<U> fork(Callable<? extends U> task);
970971

971972
/**
972-
* Starts a new thread in this scope to execute a task that does not return a
973-
* result, creating a <em>subtask</em>.
973+
* Fork a subtask by starting a new thread in this scope to execute a method that
974+
* does not return a result.
974975
*
975-
* <p> This method works exactly the same as {@link #fork(Callable)} except that
976-
* the task is provided to this method as a {@link Runnable}, the thread executes
977-
* the task's {@link Runnable#run() run} method, and its result is {@code null}.
976+
* <p> This method works exactly the same as {@link #fork(Callable)} except that the
977+
* parameter to this method is a {@link Runnable}, the new thread executes its
978+
* {@link Runnable#run() run} method, and {@link Subtask#get() Subtask.get()} returns
979+
* {@code null} if the subtask completes successfully.
978980
*
979981
* @param task the task for the thread to execute
980982
* @param <U> the result type
@@ -991,24 +993,20 @@ static <T> StructuredTaskScope<T, Void> open() {
991993
<U extends T> Subtask<U> fork(Runnable task);
992994

993995
/**
994-
* Waits for all subtasks started in this scope to complete or the scope is cancelled.
995-
* If a {@linkplain Config#withTimeout(Duration) timeout} has been set then the scope
996-
* is cancelled if the timeout expires before or while waiting.
997-
* Once finished waiting, the {@code Joiner}'s {@link Joiner#result() result} method
998-
* is invoked to get the result or throw an exception. If the {@code result} method
999-
* throws then this method throws {@code FailedException} with the exception thrown
1000-
* by the {@code result()} method as the cause.
996+
* Returns the result, or throws, after waiting for all subtasks to complete or
997+
* the scope to be <a href="#Cancallation">cancelled</a>.
1001998
*
1002-
* <p> This method waits for all subtasks by waiting for all threads {@linkplain
1003-
* #fork(Callable) started} in this scope to finish execution. It stops waiting
1004-
* when all threads finish, the {@code Joiner}'s {@link Joiner#onFork(Subtask)
1005-
* onFork} or {@link Joiner#onComplete(Subtask) onComplete} returns {@code true}
1006-
* to cancel the scope, the timeout (if set) expires, or the current thread is
1007-
* {@linkplain Thread#interrupt() interrupted}.
999+
* <p> This method waits for all subtasks started in this scope to complete or the
1000+
* scope to be cancelled. If a {@linkplain Config#withTimeout(Duration) timeout} is
1001+
* configured and the timeout expires before or while waiting, then the scope is
1002+
* cancelled and {@link TimeoutException TimeoutException} is thrown. Once finished
1003+
* waiting, the {@code Joiner}'s {@link Joiner#result() result()} method is invoked
1004+
* to get the result or throw an exception. If the {@code result()} method throws
1005+
* then this method throws {@code FailedException} with the exception as the cause.
10081006
*
10091007
* <p> This method may only be invoked by the scope owner, and only once.
10101008
*
1011-
* @return the {@link Joiner#result() result}
1009+
* @return the result
10121010
* @throws WrongThreadException if the current thread is not the scope owner
10131011
* @throws IllegalStateException if already joined or this scope is closed
10141012
* @throws FailedException if the <i>outcome</i> is an exception, thrown with the

‎src/java.base/share/classes/java/util/concurrent/StructuredTaskScopeImpl.java

+1-14
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private void ensureJoinedIfOwner() {
133133
/**
134134
* Interrupts all threads in this scope, except the current thread.
135135
*/
136-
private void implInterruptAll() {
136+
private void interruptAll() {
137137
flock.threads()
138138
.filter(t -> t != Thread.currentThread())
139139
.forEach(t -> {
@@ -143,19 +143,6 @@ private void implInterruptAll() {
143143
});
144144
}
145145

146-
@SuppressWarnings("removal")
147-
private void interruptAll() {
148-
if (System.getSecurityManager() == null) {
149-
implInterruptAll();
150-
} else {
151-
PrivilegedAction<Void> pa = () -> {
152-
implInterruptAll();
153-
return null;
154-
};
155-
AccessController.doPrivileged(pa);
156-
}
157-
}
158-
159146
/**
160147
* Cancel the scope if not already cancelled.
161148
*/

0 commit comments

Comments
 (0)
Please sign in to comment.