Suppose a thread tries to read from an empty pipe. pipe_read() does the
following:
- pipelock(), possibly sleeping
- check for buffered data
- pipeunlock()
- set PIPE_WANTR and sleep
- goto 1
pipelock() is an open-coded mutex; if a thread blocks in pipelock(), it
sleeps until the lock holder calls pipeunlock().
Both sleeps use the same wait channel. So if there are multiple threads
in pipe_read(), one thread T1 in step 3 can wake up a thread T2 sleeping
in step 4. Then T1 goes to sleep in step 4, and T2 acquires and
releases the pipelock, waking up T1 again. This can go on indefinitely,
livelocking the process.
Fix the problem by using a separate wait channel for the pipelock.
Reported by: Paul Floyd
PR: 264441