using select to handle multiple pipes; cannot figure out threadsafety