Summary:
If the user deallocates an RPC device this can sometimes fail if the RPC
server is still running. This will happen if the modification happens
while the server is still checking it. This patch adds a mutex to guard
modifications to it.
(cherry picked from commit baf7a3c1e561ff7e3f7da2261ce1012c4f2ba1c0)