RFR: 8344583: Make ArchiveWorkers lifecycle robust

Aleksey Shipilev shade at openjdk.org
Thu Nov 21 06:52:18 UTC 2024


On Thu, 21 Nov 2024 02:14:07 GMT, David Holmes <dholmes at openjdk.org> wrote:

> As far as I can tell the crash arises because we have a static `ArchiveWorkers` which embeds two `Semaphore`s. When the VM terminates and the static destructors are run, those `Semaphore`s get blown away. If the `ArchiveWorkerThreads` are still running in the process when that happens they trigger the crash.
> 
> I can't determine from this PR how the changes prevent that from happening. ??

Pool shutdown guarantees no threads are running: it coordinates with every worker to exit, and thus unblock from the semaphores. Scope object guarantees that we complete pool shutdown when leaving the scope that needs the pool. Current code has a gap that any abnormal exit between -- currently unstructured startup/shutdown -- misses the proper shutdown, which exposes us to semaphores being blown away under our feet. 

> It could perhaps be made clearer that it applies to creation/starting of all threads in this way: you must ensure the thread being started cannot run to completion and terminate and be deallocated before the starting thread can fully return from the synchronization code that is part of the thread startup protocol.

I think we are fine here: the pool never leaves threads hanging. It would wait for threads to startup if needed, and would wait for all threads to exit before completing shutdown.

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

PR Comment: https://git.openjdk.org/jdk/pull/22276#issuecomment-2490207209


More information about the hotspot-runtime-dev mailing list