Advertisement
Guest User

Coro/EV bug

a guest
Oct 15th, 2015
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.19 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use 5.14.0;
  3. use warnings;
  4.  
  5. use Coro;
  6. use EV;
  7. use AnyEvent;
  8. use Coro::AnyEvent;
  9. use Coro::Handle;
  10.  
  11. my $line1;
  12. my $line2;
  13. my $worker = async {
  14.     my $fh = unblock \*STDIN;
  15.  
  16.     eval {
  17.         $line1 = $fh->readline;
  18.     };
  19.     if ($@) {
  20.         $line1 = "interrupted reading first line: $@";
  21.     }
  22.  
  23.     eval {
  24.         $line2 = $fh->readline;
  25.     };
  26.     if ($@) {
  27.         $line2 = "interrupted reading next line: $@";
  28.     }
  29. };
  30.  
  31. Coro::AnyEvent::sleep(1);
  32. $worker->throw("interrupt\n");
  33. $worker->ready;
  34. $worker->join;
  35.  
  36. print $line1, $line2;
  37. __END__
  38.  
  39. If nothing is entered on stdin in the first second, we expect $line1 to be
  40. "interrupted reading first line: interrupt\n"
  41. but also $line2 ends up as
  42. "interrupted reading next line: recursive invocation of readable_ev or writable_ev (concurrent Coro::Handle calls on same handle?), detected at /usr/lib/perl5/Coro/Handle.pm line 551.\n"
  43.  
  44. I appreciate you can't use the same Coro::Handle instance simultaneously from two coroutines, but here only one coroutine is using it.
  45.  
  46. This is a simplified test case. The use of throw() is desired for other reasons; I know there are other possible approaches in this example.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement