Avoid deadlock if using select in multiple threads