[PATCH] D87065: Thread safety analysis: Document how try-acquire is handled

Aaron Puchert via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Sep 5 05:27:15 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG8544defdcb09: Thread safety analysis: Document how try-acquire is handled (authored by aaronpuchert).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87065/new/

https://reviews.llvm.org/D87065

Files:
  clang/docs/ThreadSafetyAnalysis.rst


Index: clang/docs/ThreadSafetyAnalysis.rst
===================================================================
--- clang/docs/ThreadSafetyAnalysis.rst
+++ clang/docs/ThreadSafetyAnalysis.rst
@@ -414,6 +414,26 @@
 indicates success, and the remaining arguments are interpreted in the same way
 as ``ACQUIRE``.  See :ref:`mutexheader`, below, for example uses.
 
+Because the analysis doesn't support conditional locking, a capability is
+treated as acquired after the first branch on the return value of a try-acquire
+function.
+
+.. code-block:: c++
+
+  Mutex mu;
+  int a GUARDED_BY(mu);
+
+  void foo() {
+    bool success = mu.TryLock();
+    a = 0;         // Warning, mu is not locked.
+    if (success) {
+      a = 0;       // Ok.
+      mu.Unlock();
+    } else {
+      a = 0;       // Warning, mu is not locked.
+    }
+  }
+
 
 ASSERT_CAPABILITY(...) and ASSERT_SHARED_CAPABILITY(...)
 --------------------------------------------------------


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87065.290080.patch
Type: text/x-patch
Size: 956 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200905/88b9f466/attachment-0001.bin>


More information about the cfe-commits mailing list