RESOLVED CONFIGURATION CHANGED 225228
CheckedLock::tryLock() use pattern should be more robust
https://bugs.webkit.org/show_bug.cgi?id=225228
Summary CheckedLock::tryLock() use pattern should be more robust
Kimmo Kinnunen
Reported 2021-04-30 05:55:53 PDT
CheckedLock::tryLock() use pattern should be more robust From bug 224970 discussions
Attachments
Patch (4.97 KB, patch)
2021-04-30 06:23 PDT, Kimmo Kinnunen
no flags
Kimmo Kinnunen
Comment 1 2021-04-30 06:21:27 PDT
Bug 224970 (In reply to Chris Dumez from comment #15) > > My preference would have been: > TryLocker locker(lock); > if (!locker.isLocked()) > return; > > This is also what Blink uses. > > I dislike any kind of adopted lock. I don't think we should be interacting > with the lock directly or adopting lock as this is a recipe for mistakes. Blink MutexTryLocker does not support thread safety analysis. As such it is equivalent of already implemented auto locker = tryHoldLock(). https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/platform/wtf/threading_primitives.h I failed to write a TryLocker that would support current implementation of thread safety analysis. Suppose we set aside the preferences for syntactical constructs for some time. The decision of what syntax to use wrt tryLock is based on which problem are you solving: A) The problem to solve is that caller forgets to adopt the lock after tryLock(). B) The problem to solve is that caller accesses the locked variables without lock. My (relatively small) experience leads to think that B is the more important problem to solve. In patch below I'm trying to communicate that the thread safety analysis already covers all of B and most of A.
Kimmo Kinnunen
Comment 2 2021-04-30 06:23:17 PDT
Radar WebKit Bug Importer
Comment 3 2021-05-07 05:56:13 PDT
Note You need to log in before you can comment on or make changes to this bug.