Skip to content

Commit

Permalink
Fix race condition in EventDispatcher
Browse files Browse the repository at this point in the history
Summary:
`mRCTEventEmitter` is used by 2 different threads. It's assigned on the UI thread and it's accessed on the JavaScript thread. Currently, it can be the case that the UI thread assigns `mRCTEventEmitter` and later the JS thread accesses it but still sees null.

This change fixes the issue by marking the `mRCTEventEmitter` variable as `volatile` to ensure that both threads see the same value for `mRCTEventEmitter`.

**Test plan (required)**

This change is currently used in my team's app. We're no longer seeing a crash in `EventDispatcher`.

Adam Comella
Microsoft Corp.
Closes #9655

Differential Revision: D3790888

Pulled By: andreicoman11

fbshipit-source-id: 68cdbc74faffb36dc2bca8ad3d4a78929badbe9c
  • Loading branch information
Adam Comella authored and Facebook Github Bot 4 committed Aug 30, 2016
1 parent 6cf7900 commit fd34844
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public int compare(Event lhs, Event rhs) {

private Event[] mEventsToDispatch = new Event[16];
private int mEventsToDispatchSize = 0;
private @Nullable RCTEventEmitter mRCTEventEmitter;
private volatile @Nullable RCTEventEmitter mRCTEventEmitter;
private final ScheduleDispatchFrameCallback mCurrentFrameCallback;
private short mNextEventTypeId = 0;
private volatile boolean mHasDispatchScheduled = false;
Expand Down

0 comments on commit fd34844

Please sign in to comment.