This is in the same vein as https://github.com/flutter/engine/pull/16081 but includes holding the mutex when updating all members in the Captures struct instead of just when tracking thread IDs.