title: Term::Readline unusual behavior
body: <p>I am creating the shell prompt using Term::Readline as given below -</p>
  
  <pre><code>my $expire_time = time + 25; # 25 sec timeout for testing and shared with thread
  my $prompt   = 'SHELL&gt; ';
  my $terminal = Term::ReadLine-&gt;new('Shell Interface');
  my $attribs  = $terminal-&gt;Attribs;
  $terminal-&gt;ornaments(0);    # disable ornaments.
  
  while ( defined( $_ = $terminal-&gt;readline($prompt) ) ) {
      if (/^\s*quit\s*$/xms) {
          # Cleanup the global parameters
          #...some cleanup code
  
          # Signal the thread to terminate, and then detach
          # it so that it will get cleaned up automatically
          # I will be using thread to control this customize shell
          $thread-&gt;kill('KILL')-&gt;detach();
          last;
          }
   }
  
   $thread = threads-&gt;create(
          sub {
              local $SIG{KILL} = sub { threads-&gt;exit() };
              eval {
                  my $buffer_interval = int( sqrt( $expire_time - time() ) );
                  my $term            = Term::ReadLine-&gt;new('Handle session of Shell');
                  $term-&gt;ornaments(0);
  
                  my $message = "Do you want to extend your session?[y/n]- ";
                INNER: while ( $expire_time &gt; time() ) {
  
                      my $diff = $expire_time - time();
                      sleep 1;
  
                      print "diff - $diff, buffer_interval - $buffer_interval\n";
  
                      if ( $diff == $buffer_interval ) {
  
                          say "Your session will expire in $diff seconds due to inactivity.";
                          while ( defined( $_ = $term-&gt;readline($message) ) )
                          {
                              if (/^y$/i) {
                                  $expire_time += $timeout;
                                  say "refreshed expire_time - $expire_time";
                              }
                              next INNER;
                          }
                      }
                  }
                  &amp;killproc('SHELL')
                    or die "cannot kill SHELL, aborting";
              };
          }
      );
  </code></pre>
  
  <p>This thread will handle the timeout of SHELL, $expire_time is set to some value say 90 seconds, the square root of timeout means 9 sec before user will be get the warning message that your session will be expire soon.. and if user will enter 'y' the session will be extended by $expire_time.</p>
  
  <p>But when the Term::ReadLine object is created in thread , it is not behaving in the right way, sometime on entering 'y' the session extend and sometime not.</p>
  
  <p><strong>Example is given below -</strong></p>
  
  <p>expire time is - 1430279631<br>
  SHELL> diff - 25, buffer_interval - 5<br>
  diff - 24, buffer_interval - 5<br>
  diff - 23, buffer_interval - 5<br>
  diff - 22, buffer_interval - 5<br>
  diff - 21, buffer_interval - 5<br>
  diff - 20, buffer_interval - 5<br>
  diff - 19, buffer_interval - 5<br>
  diff - 18, buffer_interval - 5<br>
  diff - 17, buffer_interval - 5<br>
  diff - 16, buffer_interval - 5<br>
  diff - 15, buffer_interval - 5<br>
  diff - 14, buffer_interval - 5<br>
  diff - 13, buffer_interval - 5<br>
  diff - 12, buffer_interval - 5<br>
  diff - 11, buffer_interval - 5<br>
  diff - 10, buffer_interval - 5<br>
  diff - 9, buffer_interval - 5<br>
  diff - 8, buffer_interval - 5<br>
  diff - 7, buffer_interval - 5<br>
  diff - 6, buffer_interval - 5<br>
  diff - 5, buffer_interval - 5<br>
  Your session will expire in 5 seconds due to inactivity.<br>
  Do you want to extend your session?[y/n]- y<br>
  SHELL>   </p>
  
  <p>It is not printing the message inside while() loop saying that refreshing expire time...</p>
  
  <p>Is this the problem because i am already in some Term::Readline prompt and again using the Term::Readline prompt inside one?</p>
  
  <p>Is there any flushing problem?</p>