We need to ensure that if some process sends a command to particular instance of QEMU would get its response completely, and it wouldn't go to any other process, working with same socket.
So, we would obtain an exclusive lock on virtual machine before sending command and release this lock immediately after command output is completely read (up to (qemu) prompt.
This would allow parallely executed process to get chance to send a command.
If process needs to check for qemu unsolicisted messages, it also have to obtain lock. And release just after checking.