Skip to content

Commit f38b9a9

Browse files
committed
[Threading][TSan] Update comments.
Updated the comments for tsan::acquire and tsan::release to better reflect what TSan is actually doing. rdar://110665213
1 parent 18b359f commit f38b9a9

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

include/swift/Threading/ThreadSanitizer.h

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,35 @@ inline bool enabled() {
6363
return threading_impl::_swift_tsan_enabled;
6464
}
6565

66-
/// Indicate to TSan that an acquiring load has occurred on the current
67-
/// thread. If some other thread does a releasing store with the same
68-
/// pointer, we are indicating to TSan that all writes that happened
69-
/// before that store will be visible to the current thread after the
70-
/// `acquire()`.
66+
/// Inform TSan about a synchronization operation.
67+
///
68+
/// This is used when TSan cannot see the synchronization operation, for
69+
/// example, if it is using a custom primitive for which TSan doesn't have
70+
/// a built-in interceptor. This does not necessarily mean a lock or a C(++)
71+
/// atomic operation - it could be any kind of synchronization mechanism.
72+
///
73+
/// An acquire-release pair using the same address establishes an ordering
74+
/// constraint in TSan's happens-before graph, which TSan uses to determine
75+
/// whether two memory accesses from different threads have a well-defined
76+
/// order.
77+
///
78+
/// For instance, in
79+
///
80+
/// Thread 1 Thread 2
81+
///
82+
/// access to y
83+
/// tsan::release(x)
84+
/// lock given away
85+
///
86+
/// --> sync point -->
87+
///
88+
/// lock taken
89+
/// tsan::acquire(x)
90+
/// access to y
91+
///
92+
/// the access to y from Thread 2 is safe relative to the preceding access to
93+
/// y on Thread 1 because it is preceded by an acquire of x that was itself
94+
/// preceded by a release of x.
7195
template <typename T>
7296
T *acquire(T *ptr) {
7397
if (threading_impl::_swift_tsan_acquire) {
@@ -76,10 +100,9 @@ T *acquire(T *ptr) {
76100
return ptr;
77101
}
78102

79-
/// Indicate to TSan that a releasing store has occurred on the current
80-
/// thread. If some other thread does an acquiring load with the same
81-
/// pointer, we are indicating to TSan that that thread will be able to
82-
/// see all writes that happened before the `release()`.
103+
/// Inform TSan about a synchronization operation.
104+
///
105+
/// This is the counterpart to tsan::acquire.
83106
template <typename T>
84107
T *release(T *ptr) {
85108
if (threading_impl::_swift_tsan_release) {

0 commit comments

Comments
 (0)