[RFC] Implement c10::Synchronized<T>, a basic error-avoiding synchronization wrapper for data (#73407)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/73407
After adding mutex/lock in a previous change, I realized that `folly::Synchronized<T>` exists for this reason. However, we can't use it, so I have implemented a basic version for use in `c10` in this change.
Reviewers, please check if this looks reasonable as a minimal first step to enforce that data that is supposed to be used in a multi-threaded context ends up being locked before use. i.e. don't rely on the developer to do the right thing, instead enforce it using this abstraction.
ghstack-source-id: 150327548
Test Plan: See the next diff in this stack for the text plan.
Reviewed By: pavithranrao
Differential Revision: D34465420
fbshipit-source-id: 76c921e9b78ff2dfc82a0bfc83ffc8fb232e2f21
(cherry picked from commit 5882fe2022dd4a83ed259e6b6fe255e8b37e7d81)