@@ -13,17 +13,21 @@ import Glibc
13
13
var StringTestSuite = TestSuite ( " String " )
14
14
15
15
extension String {
16
- var bufferID : UInt {
17
- return unsafeBitCast ( _core. _owner, to: UInt . self)
18
- }
19
16
var capacityInBytes : Int {
20
17
return _core. nativeBuffer!. capacity
21
18
}
22
19
}
23
20
24
- // Swift.String has an optimization that allows us to append to a shared string
25
- // buffer. Make sure that it works correctly when two threads try to append to
26
- // different non-shared strings that point to the same shared buffer.
21
+ // Swift.String used to hsve an optimization that allowed us to append to a
22
+ // shared string buffer. However, as lock-free programming invariably does, it
23
+ // introduced a race condition [rdar://25398370 Data Race in StringBuffer.append
24
+ // (found by TSan)].
25
+ //
26
+ // These tests verify that it works correctly when two threads try to append to
27
+ // different non-shared strings that point to the same shared buffer. They used
28
+ // to verify that the first append could succeed without reallocation even if
29
+ // the string was held by another thread, but that has been removed. This could
30
+ // still be an effective thread-safety test, though.
27
31
28
32
enum ThreadID {
29
33
case Primary
@@ -79,11 +83,6 @@ func sliceConcurrentAppendThread(_ tid: ThreadID) {
79
83
secondaryString = privateString
80
84
}
81
85
barrier ( )
82
- if tid == . Primary {
83
- expectTrue (
84
- ( privateString. bufferID == sharedString. bufferID) !=
85
- ( secondaryString. bufferID == sharedString. bufferID) )
86
- }
87
86
}
88
87
}
89
88
0 commit comments