This change is intended to fix intermittent failures in ipc_tests unit test and rpc_misc.py functional tests that happen on mac os, which sometimes fail with error terminating due to uncaught exception of type std::__1::system_error: mutex lock failed: Invalid argument as reported https://github.com/chaincodelabs/libmultiprocess/issues/154
This error could happen when m_loop.reset(); in CapnpProtocol::startLoop executes before the m_loop->removeClient(lock); method returns in the ~CapnpProtocol destructor , causing an failure to reacquire the EventLoop::m_mutex inside the EventLoop::removeClient method, and the “mutex lock failed” exception to be thrown.
Fix this error by adding a new mutex to guard the CapnpProtocol::m_loop variable and making sure m_loop.reset(); cannot be called until after m_loop->removeClient(lock); returns.
This PR is part of the process separation project.