Monitor + killing thread => thread in an aborting state

Discussion in 'Ruby' started by Christopher Debski, Feb 22, 2009.

  1. Hi
    I am using ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32].
    I have made a small program, to see whether killing thread is safe, when
    it is using a monitor.
    I have 3 threads:
    -writer, which changes global resource guarded by monitor
    -interrupter, which kills and spawns writer in a loop
    -main, which only monitors other threads

    After a few seconds my program hangs, because kill method does not
    return. Main thread says that the writer thread is in an aborting state.

    Sample output:
    writer: ok?
    main: tick writer-#<Thread:0x3b4b1e run> interrupter-#<Thread:0x1a80aea
    run>
    interrupter: kill
    interrupter: join
    interrupter: sleep 1
    interrupter: new
    interrupter: sleep 2
    writer: ok?
    interrupter: kill
    main: tick writer-#<Thread:0x1b66b06 aborting>
    interrupter-#<Thread:0x1a80aea run>
    main: tick writer-#<Thread:0x1b66b06 aborting>
    interrupter-#<Thread:0x1a80aea run>
    main: tick writer-#<Thread:0x1b66b06 aborting>
    interrupter-#<Thread:0x1a80aea run>
    (repeats infinitely)

    Is it ruby's bug?
    See attachment for full program source.

    Regards,
    Christopher

    Attachments:
    http://www.ruby-forum.com/attachment/3328/rubyMon.txt

    --
    Posted via http://www.ruby-forum.com/.
     
    Christopher Debski, Feb 22, 2009
    #1
    1. Advertisements

  2. Christopher Debski

    Alex Katebi Guest

    [Note: parts of this message were removed to make it a legal post.]

    For one thing you should use ruby 1.9 which uses the OS thread instead of
    native ruby threading. The other is when you kill or cancel thread you need
    to provide safe areas for your condemned thread to die so resources are
    releases if any used.
    Look into pthread about canceling.

    On Sun, Feb 22, 2009 at 11:34 AM, Christopher Debski <
    > wrote:

    > Hi
    > I am using ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32].
    > I have made a small program, to see whether killing thread is safe, when
    > it is using a monitor.
    > I have 3 threads:
    > -writer, which changes global resource guarded by monitor
    > -interrupter, which kills and spawns writer in a loop
    > -main, which only monitors other threads
    >
    > After a few seconds my program hangs, because kill method does not
    > return. Main thread says that the writer thread is in an aborting state.
    >
    > Sample output:
    > writer: ok?
    > main: tick writer-#<Thread:0x3b4b1e run> interrupter-#<Thread:0x1a80aea
    > run>
    > interrupter: kill
    > interrupter: join
    > interrupter: sleep 1
    > interrupter: new
    > interrupter: sleep 2
    > writer: ok?
    > interrupter: kill
    > main: tick writer-#<Thread:0x1b66b06 aborting>
    > interrupter-#<Thread:0x1a80aea run>
    > main: tick writer-#<Thread:0x1b66b06 aborting>
    > interrupter-#<Thread:0x1a80aea run>
    > main: tick writer-#<Thread:0x1b66b06 aborting>
    > interrupter-#<Thread:0x1a80aea run>
    > (repeats infinitely)
    >
    > Is it ruby's bug?
    > See attachment for full program source.
    >
    > Regards,
    > Christopher
    >
    > Attachments:
    > http://www.ruby-forum.com/attachment/3328/rubyMon.txt
    >
    > --
    > Posted via http://www.ruby-forum.com/.
    >
    >
     
    Alex Katebi, Feb 22, 2009
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jerry Camel

    Stop aborting my thread!

    Jerry Camel, Feb 25, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    778
    Kevin Spencer
    Feb 26, 2004
  2. ABC
    Replies:
    2
    Views:
    4,691
    Scott Allen
    Jan 9, 2006
  3. James Lamanna

    Killing a python thread with a signal

    James Lamanna, Dec 22, 2004, in forum: Python
    Replies:
    0
    Views:
    470
    James Lamanna
    Dec 22, 2004
  4. =?ISO-8859-2?Q?Jacek_Pop=B3awski?=

    killing thread after timeout

    =?ISO-8859-2?Q?Jacek_Pop=B3awski?=, Sep 6, 2005, in forum: Python
    Replies:
    10
    Views:
    920
    Bryan Olson
    Sep 8, 2005
  5. Russ
    Replies:
    5
    Views:
    571
    Fabrizio Milo
    Feb 19, 2006
  6. Carl J. Van Arsdall

    Re: Killing a thread

    Carl J. Van Arsdall, Jun 10, 2006, in forum: Python
    Replies:
    3
    Views:
    516
    Antoon Pardon
    Jun 12, 2006
  7. Fredrik Lundh

    Re: Killing a thread

    Fredrik Lundh, Jun 10, 2006, in forum: Python
    Replies:
    4
    Views:
    392
    Fredrik Lundh
    Jun 11, 2006
  8. ScottZ
    Replies:
    2
    Views:
    599
    Jorgen Grahn
    Nov 2, 2008
Loading...