Replace direct use of mutex/cond with monitor.