Fix race condition in torch::jit::Function (#27009)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/27009
JIT can be called concurrently from two threads, so even the read from GraphExecutor has to be guarded by the lock.
This was a recent regression introduced by https://github.com/pytorch/pytorch/pull/26571/files#diff-40af5094abe4f522e8a78adb591dde19
Reviewed By: jamesr66a, wanchaol
Differential Revision: D17645407
fbshipit-source-id: f0a3a5d6d8ced04e043bdc56f4263f91d6189be1