On Thu, 3 Apr 2025 12:54:01 GMT, Per Minborg <pminb...@openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/StableValue.java line 402:
>> 
>>> 400:  * race. Since stable functions and stable collections are built on 
>>> top of
>>> 401:  * {@linkplain StableValue#orElseSet(Supplier) orElseSet()} they too 
>>> are
>>> 402:  * thread safe and guarantee at-most-once-per-input invocation.
>> 
>> Do we guarantee that there is a total order with respect to the suppliers 
>> that fail to return. You can take a look at the specification of 
>> [`std::call_once`](https://en.cppreference.com/w/cpp/thread/call_once)
>> 
>>> All active calls on the same flag form a single total order consisting of 
>>> zero or more exceptional calls, followed by one returning call. The end of 
>>> each active call synchronizes-with the next active call in that order.
>>> The return from the returning call synchronizes-with the returns from all 
>>> passive calls on the same flag: this means that all concurrent calls to 
>>> std::call_once are guaranteed to observe any side-effects made by the 
>>> active call, with no additional synchronization.
>
> I don't think we should promise this even though it might be the case.

What is the benefit of not promising it? Promising helps the supplier to have a 
well-defined order of execution. Furthermore, even if you do not promise it, it 
is the only possible implementation now and people will depend on it regardless.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/23972#discussion_r2027128199

Reply via email to