[Profiler] Add missing guards (#65812)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/65812
Multiple threads are recording events to a shared activity buffer and the buffer is at some point transferred to libkineto.
The access to and the transfer of the buffer needs to be done under lock.
Reviewed By: leitian, xw285cornell
Differential Revision: D31220061
fbshipit-source-id: f11c879df1b55aa9068187e600730bb0e5e5455f