RFR: 8268638: semaphores of AsyncLogWriter may be broken when JVM is exiting. [v2]
David Holmes
dholmes at openjdk.java.net
Tue Jun 15 01:59:45 UTC 2021
On Tue, 15 Jun 2021 01:55:28 GMT, David Holmes <dholmes at openjdk.org> wrote:
>> Thanks. I remove Semaphore::value() and declare friend class SemaphoreLocker there.
>>
>> My intention is to do a sanity check. A semaphore can be used to implement a low-level lock if and only if its value is 1. It means that only one thread can enter the critical region at any time. However, it's error-prone for the RAII class to accept any arbitrary semaphore. It's because its value could be any non-negative number.
>
> I guess I wasn't clear enough.
>
> Please do not make any changes to the Semaphore class. This "value" is not needed in general and not needed for your sanity checking.
>
> The Semaphore _lock is defined in the AsyncLogWriter class and initialized to 1 so it can be used to mimic a mutual exclusion lock. This does not need to be sanity checked as it is all handled within a small chunk of code. The AsyncLogLocker does not take a semaphore, it is a friend of AsyncLogWriter and accesses _lock directly.
>
> Thanks,
> David
PS. If it were warranted, the way to do your "sanity check" would be to introduce a BinarySemaphore class that always initializes to a count of 1. But we do not need this.
-------------
PR: https://git.openjdk.java.net/jdk/pull/4479
More information about the hotspot-runtime-dev
mailing list