1

What sorts of crashes can a lack of threadsafety cause? (Sort of a follow-up to Under what circumstances are atomic properties useful?).

Can anyone reproduce a crash example (even if sporadically) with a test case?

I'm trying to sort out from a large number of crash logs what percent of them are related to a particular integer variable being accessed from multiple threads. (Yes, I've already confirmed that this access can happen in my iOS app, the question is just how often does it happen.)

Obviously improper variable access can lead to unexpected effects and more crashes downstream, but I'm interested only in those related directly to the access/mutation of the variable (since downstream effects won't generally be the same from one app to another). Also, only interested in integer (or other completely immutable) variables.

I'm seeking any example error codes / exceptions / crash logs from which I can extract keywords and regular expressions. Even better would be a test app or unit test case which can reproduce a crash with high probability. I tried a simple example in a unit test but couldn't seem to cause a crash.

cbutton9
  • 148
  • 6
  • @Rob, thanks! I'm not trying to identify my particular race condition (which is what it looks like TSan is for) - I already know where it is. I'm just trying to understand exactly how it would manifest in a crash. – cbutton9 Jan 13 '18 at 01:34
  • I'm working on fixing it, but I also want to identify the effect of this crash on my app and the user experience overall (for organizational and prioritization reasons). – cbutton9 Jan 13 '18 at 01:35

1 Answers1

1

While this approach sounds so logical, race conditions manifest themselves in manifold ways and defy simple characterization within crash logs. Problems arising from data races are particularly vexing because they often result in heisenbugs. And sometimes it doesn't even crash but rather just produces incorrect results (which may or may not result in other problems).

I know this isn't the answer you're looking for, but while I can see the appeal of your plan, it is unlikely to be a productive exercise.

If it's a question of prioritizing the thread-safety fix versus other issues, there is no simple answer. The app is just going to be susceptible to crashes and other unpredictable behavior until this data race issue is resolved. But we can't reliably forecast what percentage of your current crash logs will be addressed. IMHO, given that crashing is the quickest way to lose a user-base, this thread-safety fix strikes me as a very high priority.


In terms of identifying the unsynchronized access, the thread sanitizer, as outlined in this WWDC video, is a excellent tool.

Rob
  • 371,891
  • 67
  • 713
  • 902