I'm using some Firebase tools, and was debugging with the thread sanitizer enabled when I received a warning about a data race on some internal library objects. Here is the TSAN output that appeared in my Xcode console:
==================
WARNING: ThreadSanitizer: race on NSMutableArray (pid=70981)
Read-only access of NSMutableArray at 0x7b0c0019b240 by thread T21:
#0 -[__NSArrayM countByEnumeratingWithState:objects:count:] <null>:1061136 (CoreFoundation:x86_64+0x72df8)
#1 +[GPBMessage resolveInstanceMethod:] <null>:1061136 (Target:x86_64+0x101e05b2f)
#2 _dispatch_client_callout <null>:1061136 (libdispatch.dylib:x86_64+0x37eb)
Previous modifying access of NSMutableArray at 0x7b0c0019b240 by thread T15:
#0 -[__NSArrayM addObject:] <null>:1061136 (CoreFoundation:x86_64+0x27d88)
#1 +[GPBDescriptor allocDescriptorForClass:rootClass:file:fields:fieldCount:storageSize:flags:] <null>:1061136 (Target:x86_64+0x101dd2bd4)
#2 _dispatch_client_callout <null>:1061136 (libdispatch.dylib:x86_64+0x37eb)
Location is heap block of size 40 at 0x7b0c0019b240 allocated by thread T15:
#0 calloc <null>:1061152 (libclang_rt.tsan_iossim_dynamic.dylib:x86_64+0x471a2)
#1 class_createInstance <null>:1061152 (libobjc.A.dylib:x86_64+0xf37f)
#2 _dispatch_client_callout <null>:1061152 (libdispatch.dylib:x86_64+0x37eb)
Thread T21 (tid=8959546, running) is a GCD worker thread
Thread T15 (tid=8956171, running) is a GCD worker thread
SUMMARY: ThreadSanitizer: race on NSMutableArray (CoreFoundation:x86_64+0x72df8) in -[__NSArrayM countByEnumeratingWithState:objects:count:]
==================
(lldb) thread info -s
thread #38: tid = 0x88b63a, 0x00000001129976a0 libclang_rt.tsan_iossim_dynamic.dylib`__tsan_on_report, queue = 'CCTClearcutUploader', stop reason = Race on a library object detected
{
"all_addresses_are_same" : true,
"description" : "Race on a library object",
"instrumentation_class" : "ThreadSanitizer",
"issue_type" : "external-race",
"location_description" : "Location is a 40-byte heap object at 0x7b0c0019b240",
"locs" : [
{
"address" : 0,
"file_descriptor" : 0,
"index" : 0,
"object_type" : "",
"size" : 40,
"start" : 135291471508032,
"suppressable" : 0,
"thread_id" : 16,
"trace" : [
4606939555,
4713079680,
4854634476
],
"type" : "heap"
}
],
"memory_address" : 135291471508032,
"mops" : [
{
"address" : 135291471508032,
"index" : 0,
"is_atomic" : false,
"is_write" : false,
"size" : 1,
"thread_id" : 38,
"trace" : [
4737015289,
4568242992,
4854634476
]
},
{
"address" : 135291471508032,
"index" : 1,
"is_atomic" : false,
"is_write" : true,
"size" : 1,
"thread_id" : 16,
"trace" : [
4736707977,
4568034261,
4854634476
]
}
],
"mutexes" : [
],
"report_count" : 0,
"sleep_trace" : [
],
"stacks" : [
],
"stop_description" : "Race on a library object detected",
"summary" : "Race on a library object in +[GPBMessage resolveInstanceMethod:] at 0x7b0c0019b240",
"threads" : [
{
"index" : 0,
"name" : "",
"parent_thread_id" : 0,
"running" : 1,
"thread_id" : 38,
"thread_os_id" : 8959546,
"trace" : [
4606805902,
4761944576,
4854634476
]
},
{
"index" : 1,
"name" : "",
"parent_thread_id" : 0,
"running" : 1,
"thread_id" : 16,
"thread_os_id" : 8956171,
"trace" : [
]
}
],
"unique_tids" : [
]
}