Skip to content

Commit

Permalink
Fix data race on read/write _instance variable in ModuleData class
Browse files Browse the repository at this point in the history
Summary:
Thanks for submitting a PR! Please read these instructions carefully:

- [ ] Explain the **motivation** for making this change.
- [ ] Provide a **test plan** demonstrating that the code is solid.
- [ ] Match the **code formatting** of the rest of the codebase.
- [ ] Target the `master` branch, NOT a "stable" branch.

What existing problem does the pull request solve?
XCode  [Thread Sanitizer](https://clang.llvm.org/docs/ThreadSanitizer.html) find race condition while read/write `_instance` variable in RCTModuleData class. A bridge can check `hasInstance` method while instance writes.

All tests passed on my device.
These changes remove data race, you can turn it in scheme configuration ![](https://www.shinobicontrols.com/wp-content/uploads/2016/08/Enable_Sanitizer.png)
Closes #13757

Differential Revision: D4994041

Pulled By: javache

fbshipit-source-id: 631cd59bbcbde193937d8baf8358ff6868717a2e
  • Loading branch information
makadaw authored and facebook-github-bot committed May 24, 2017
1 parent 457616f commit 5e97be8
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions React/Base/RCTModuleData.mm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ - (void)setUpMethodQueue


- (BOOL)hasInstance - (BOOL)hasInstance
{ {
std::unique_lock<std::mutex> lock(_instanceLock);
return _instance != nil; return _instance != nil;
} }


Expand Down

0 comments on commit 5e97be8

Please sign in to comment.