Forum: Ruby Different behaviour of control-c for 1.9.2-p290/2.0.0-p0

Posted by Bernd Kiefer (r4me)
on 2013-03-15 22:24
Hello,

why can the following example code be successfully stopped by control-c
using ruby 1.9.2-p290 but NOT using ruby 2.0.0-p0 (control-c is ignored)
?

Any idea ?

Cheers


require 'ffi-inliner'
require 'fiber'

module Test

  extend FFI::Library
  extend Inliner

  inline <<-'EOF'
  // *****************************************************
  // * Shared library functions
  // *****************************************************
  unsigned int i = 0;
  void func1() {
    printf("Starting func1\n");
    while(1) {
  my_wait(1);
//  printf("Loop func1: %u\n", i);
  i++;
    }
  }
  void func2() {
    printf("Starting func2\n");
    while(1) {
  my_wait(2);
//  printf("Loop func2: %u\n", i);
    }
  }
  // *****************************************************
  // * Bridge functions
  // *****************************************************
  void (*my_wait_function)(unsigned int);
  void register_my_wait_function(void *p) {
  my_wait_function = p;
  }
  void my_wait(unsigned int i) {
  (*my_wait_function)(i);
  }
  EOF

  callback        :cb_my_wait,                [:uint],       :void
  attach_function :register_my_wait_function, [:cb_my_wait], :void
  attach_function :func1,                     [],            :void
  attach_function :func2,                     [],            :void

  attach_variable :i, :uint


  FUNC = Proc.new do
    |id|

    if id==1
      @fib2.resume
    else
      p i if (i%100000)==0
      Fiber.yield
    end
  end

  register_my_wait_function FUNC

  self.i = 0

  @fib1 = Fiber.new do
    func1
  end

  @fib2 = Fiber.new do
    func2
  end

  @fib1.resume

end
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.