From dba25fa96643bdadc9bad85b20d35e106885f8e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Knutzen?= <2263015+hakonk@users.noreply.github.com> Date: Fri, 28 Jun 2024 08:11:34 -0700 Subject: [PATCH] Data race related to reading/writing to `AllocationTestModule.valid` (#45191) Summary: The fix entails making `AllocationTestModule.valid` an Objective-C atomic property and funneling access to the ivar via the synthesized property getter and setter. While the data race was present in test code, it would make it more difficult to spot more severe data races with the TSan. Also, getting rid of a data race is always good. ## Changelog: [iOS][Fixed] - Data race related to access of `AllocationTestModule.valid` Pull Request resolved: https://github.com/facebook/react-native/pull/45191 Test Plan: `RCTAllocationTests` will test the implementation of `AllocationTestModule`. Reviewed By: christophpurrer Differential Revision: D59155083 Pulled By: javache fbshipit-source-id: e3217cffd0801377a25f04bf8ed0b4e2d1d88498 --- packages/rn-tester/RNTesterUnitTests/RCTAllocationTests.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/rn-tester/RNTesterUnitTests/RCTAllocationTests.m b/packages/rn-tester/RNTesterUnitTests/RCTAllocationTests.m index ea66d188978..ed1f3a7e5da 100644 --- a/packages/rn-tester/RNTesterUnitTests/RCTAllocationTests.m +++ b/packages/rn-tester/RNTesterUnitTests/RCTAllocationTests.m @@ -16,7 +16,7 @@ @interface AllocationTestModule : NSObject -@property (nonatomic, assign, getter=isValid) BOOL valid; +@property (atomic, assign, getter=isValid) BOOL valid; @end @@ -27,14 +27,14 @@ RCT_EXPORT_MODULE(); - (instancetype)init { if ((self = [super init])) { - _valid = YES; + self.valid = YES; } return self; } - (void)invalidate { - _valid = NO; + self.valid = NO; } RCT_EXPORT_METHOD(test