On Mon, 22 Apr 2024 19:49:44 GMT, Brian Burkhalter <b...@openjdk.org> wrote:

>> Prevent blocking due to a carrier thread not being released when 
>> `ByteArrayOutputStream.writeTo` is invoked from a virtual thread.
>
> Brian Burkhalter has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Correct ID in test @bug tag

As a temporary workaround then I think this is okay. It does mean there needs 
to a heap spec for the snapshot. Aside from that, the behavioral difference 
should only be observable to something that is relying on unspecified behavior. 
BAOS does not document anything about thread safety or that its methods are 
synchronized.

test/jdk/java/io/ByteArrayOutputStream/WriteToReleasesCarrier.java line 78:

> 76:                 }
> 77:             } finally {
> 78:                 LockSupport.unpark(vthread1);

It might be clearer if you add vthread1.join() after the unpark. It's not 
strictly needed here as scheduler::close will block until the carrier 
terminates so that will guarantee that the virtual thread has unmounted.

test/jdk/java/io/ByteArrayOutputStream/WriteToReleasesCarrier.java line 124:

> 122:      * Returns a builder to create virtual threads that use the given 
> scheduler.
> 123:      */
> 124:     static Thread.Builder.OfVirtual virtualThreadBuilder(Executor 
> scheduler) throws Exception {

At some point we will move some of the infrastructure for tests like this to a 
shared location in the test tree.

-------------

Marked as reviewed by alanb (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/18901#pullrequestreview-2016331774
PR Review Comment: https://git.openjdk.org/jdk/pull/18901#discussion_r1575700125
PR Review Comment: https://git.openjdk.org/jdk/pull/18901#discussion_r1575700737

Reply via email to