I've mentioned this to Julian in person: The code change look good to me, but any changes in this piece of code need a high level of manual testing as this code is very critical and has potential for breaking something even with innocent changes like this.
@yln The description of this change needs improving. The title probably ought to be "[TSan] The "thread_terminate" event is always delivered on the terminating thread" and then that should be followed with a brief justification along with a radar number (if there is one).
I don't know if the invariant you're adding is actually true so I can't really comment on that.
Does this comment need updating? The comment and your change together imply that the PTHREAD_INTROSPECTION_THREAD_TERMINATE event only happens on GCD worker threads. Is that right?