Avoid wait() deadlocks with communicate()