Repository navigation
fix(libkernel): treat a null deadline as an untimed lock in the timed pthread locks - #7035
Conversation
… pthread locks pthread_rwlock_timedrdlock, pthread_rwlock_timedwrlock and pthread_mutex_timedlock threw for a null abstime. FreeBSD's libthr passes a null abstime on to the untimed kernel lock, so these calls then wait like pthread_rwlock_rdlock, pthread_rwlock_wrlock and pthread_mutex_lock. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Windows run in #7023 (comment): both tests pass 3/3, and with the source reverted both throw "null abstime". guest_pthread_timed_locks aborted in 15 of 20 runs on a heavily loaded host and passed 20 of 20 on a quieter one. Every abort was the elapsed >= HoldTime / 2 check, after the main thread saw held 40-90 ms late; the lock was always taken after the holder unlocked. A flag the holder sets just before unlocking, checked when acquire() returns, would make the test deterministic. Written with Claude Code assistance (validation by a subagent, reviewed in this session). |
…not elapsed time The waiter took the lock only after the holder unlocked, but under load it saw the holder's lock late and measured less than half the hold time. The holder now sets a flag just before it unlocks and the waiter requires it once its lock is taken. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @screamm, that diagnosis was right. The lock was taken only after the holder unlocked, so the half-hold-time check was measuring scheduler delay. c7849f8 does what you suggested: the holder sets AI-assisted: yes (Claude Code) |
|
Rechecked on head
The Not checked: full build, the non-GPU suite, Linux, title runs. Written with Claude Code assistance (validation by a subagent, reviewed in this session). |
What
pthread_rwlock_timedrdlock,pthread_rwlock_timedwrlockandpthread_mutex_timedlockthrewstd::runtime_error(null abstime) for a null deadline. In FreeBSD 11's libthr, a nullabstimereaches the untimed kernel lock:rwlock_rdlock_commonandrwlock_wrlock_commoncheck the deadline only when it isn't null and pass it to__thr_rwlock_rdlock/__thr_rwlock_wrlock, where null means no timeout.mutex_lock_sleepcalls__thr_umutex_lockwhenabstime == NULL, andmutex_self_lockreturnsEDEADLKfor an error-checking mutex the caller already holds, aspthread_mutex_lockdoes.The three calls now do what
pthread_rwlock_rdlock,pthread_rwlock_wrlockandpthread_mutex_lockdo whenabstimeis null.I don't know of a title that hits this. I found it while comparing the pthread wrappers with libthr.
Tested
Ubuntu 24.04, GCC 13.3, Release, on
main6a32550.guest_pthread_timed_locks(new): with a null deadline, both rwlock calls take a free lock, and each waits for a writer that holds the lock for 50 ms, then takes it.pthread_mutex_timedlocktakes a free mutex, returnsEDEADLKwhen the caller already holds it, and waits for another holder the same way. Withmain'sRwlock.cpp, and separately withmain'sMutex.cpp, the test aborts at the first null deadline in that file (the throw). With this change it passes 3 of 3.guest_pthread_rwlock: its check that a null deadline throws now expects the lock to be taken and released. Withmain'sRwlock.cppthat check fails.ctest -R '^guest_|libc': 403 of 403 pass, with this and one other small libkernel fix applied together.null abstime(series run by @screamm).tools/check_conventions.pypasses.tools/pr_overlap.pyfinds no conflicting lines, and the new test is registered away from where fix(libkernel): notify rwlock waiters before unlocking state #6711 adds one (git merge-treemerges this branch with fix(libkernel): notify rwlock waiters before unlocking state #6711, fix(libkernel): keep a finished Windows thread's stack until it is joined or detached #4563, fix(libkernel): report thread guard size from attribute queries #6893 and fix(libkernel): return EINVAL for pthread mutex and cond operations on a destroyed object #6244 cleanly). It couldn't compare against seven PRs that conflict withmainand touchCMakeLists.txt(test: organize library tests and label CTest suites #6044 also movesGuestPthreadRwlock.cpp).@screamm rechecked c7849f849 on Windows:
guest_pthread_timed_lockspasses 20 of 20 direct runs on a loaded host (where it had aborted 15 of 20) and 20 of 20 next to an 8-job build; both tests abort withmain'sMutex.cppandRwlock.cpp.Not checked: macOS, a console.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code