[crac] RFR: Wake up all TIMED_WAITING threads after restore

Radim Vansa rvansa at openjdk.org
Tue Jun 20 06:40:36 UTC 2023


On Mon, 19 Jun 2023 15:52:04 GMT, Anton Kozlov <akozlov at openjdk.org> wrote:

>> This is a fix for an issue found by @jankratochvil when testing #53: Threads that enter sleep or timed parking use absolute monotonic time for pthread_cond_wait(). When the monotonic time changes during C/R we need to wake all threads to readjust the timeout to the new absolute time.
>> 
>> This introduces effectively a spurious wakeup; this is permitted for all the uses of pthread_timed_wait. Implementation either handles that transparently or propagates the wakeup to Java.
>> 
>> This commit does not handle timed waiting in non-Java threads other than WatcherThread.
>
> src/hotspot/os/linux/os_linux.cpp line 6132:
> 
>> 6130:       t->interrupt();
>> 6131:       t->osthread()->set_interrupted(false);
>> 6132:     }
> 
> I think the problem of the native implementation of the timed wait is being fixed on the wrong level of abstraction. The interrupt() is much higher leve operation than the pthread_cond_signal, that we are actually targeting. And the latter would be also much cheaper. Could you replace the code with signaling every cond?

We are not triggering the Java InterruptedException; when you look into the implementation of `JavaThread::interrupt` you'll see that unparking from those 3 types of conditions is all it's actually doing, setting and immediately unsetting the interrupted flag is a noop on posix systems.
So I don't think this can be any cheaper. We are operating on a bit higher level only to reuse code that we would otherwise inline in here.

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

PR Review Comment: https://git.openjdk.org/crac/pull/85#discussion_r1234801665


More information about the crac-dev mailing list