title: why is my PipedOutputStream deadlocking?
body: <p>I am trying to implement a threaded circular buffer with PipedInputStream &amp; PipedOutputStream but it is locking everytime when I get to mHead.write in the Decoder runnable. I thought there was no chance for deadlocks when using separate threads.</p>
  
  <pre><code>    private class DecoderTask implements Runnable{
  
      @Override
      public void run() {
          while(!mStop){
              try {
                      Log.d(TAG,"trying to write");
          mHead.write(decode( 0, 1000));
              mHead.flush();
              Log.d(TAG,"Decoded");
              } catch (DecoderException e) {
                  Log.e(TAG,e.toString());
              } catch (IOException e) {
                  Log.e(TAG,e.toString());
              }
          }
      }
  
  }
  private class WriteTask implements Runnable{
  
      @Override
      public void run() {
          while(!mStop){
              try {
                                   Log.d(TAG,"trying to read");
                   int read = mTail.read(mByteSlave, 0, mByteSlave.length);
                   mAudioTrack.flush();
                                   mAudioTrack.write(mByteSlave,0,read);
                                   Log.d(TAG,"read");                 
              } catch (IOException e) {
                  Log.e(TAG,e.toString());
              }
          }
      }
  
  }
  
  
  //in some function
  mTail = new PipedInputStream();
  mHead = new PipedOutputStream(mTail);
  mByteSlave = new byte[BUF];
  mT1 = new Thread(new DecoderTask(), "Reader");
  mT2 = new Thread(new WriteTask(), "Writer");
  mT1.start();
  mT2.start();
  return;
  </code></pre>
  
  <p>edit:  here is the full source for my service <a href="http://pastie.org/1179792" rel="nofollow">http://pastie.org/1179792</a></p>
  
  <p>logcat prints out :</p>
  
  <p>trying to read<br>
  trying to write</p>