I've found that FMultiReaderSingleWriterGT has at least 2 bugs:

The one that caused a deadlock in our game and caused me to investigate was this:

  1. Worker Thread Acquires Read lock
  2. Game Thread Acquires Read lock (Steps 1 and 2 can happen in either order)
  3. Worker Thread Releases Read lock
  4. Game Thread Releases Read lock
  5. Game Thread attempts to acquire Write lock (Deadlocks here)

This is deadlocked because ReadCounter is 0, but Action is left set as ReadingAction when the game thread releases the lock. Removing the IsInGameThread() guards in LockRead() and UnlockRead() would fix this.

I also noticed there is also a more standard problem that occurs with these kinds of lock, that the control data isn't guarded, so you can get two threads modifying the lock in this pattern:

  1. Thread 1 - In LockRead Sets action to ReadingAction and Increments ReadCounter to 1
  2. Thread 2 - In Lock Read Sets ReadingAction,
  3. Thread 1 - In UnlockRead Decrements ReadCounter to 0 and sets action to NoAction
  4. Thread 2 - Increments ReadCounter to 1

Result: Thread 2 is reading, but lock is set to NoAction.

Steps to Reproduce


Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-30929 in the post.

Login to Vote

ComponentUE - Foundation - Core
Affects Versions4.104.11
Target Fix4.15
Fix Commit3214800
Main Commit3228932
Release Commit3240724
CreatedMay 17, 2016
ResolvedNov 30, 2016
UpdatedApr 27, 2018