Reclaiming locks

Discussion in 'C Programming' started by CJ, Oct 29, 2007.

  1. CJ

    CJ Guest

    Hello Friends -

    I've run across the following situation. I have two threads, say T1 and
    T2 which access shared data - each locks a mutex before doing so.

    Now I have a hard-to-find bug which means that periodically T1 gets
    killed unexpectedly. But if it holds the mutex at that point, T2 blocks
    for ever!

    How can I get T1 to release any locks it's holding when it gets killed?
    CJ, Oct 29, 2007
    #1
    1. Advertising

  2. CJ <> writes:

    > Hello Friends -
    >
    > I've run across the following situation. I have two threads, say T1 and
    > T2 which access shared data - each locks a mutex before doing so.
    >
    > Now I have a hard-to-find bug which means that periodically T1 gets
    > killed unexpectedly. But if it holds the mutex at that point, T2 blocks
    > for ever!
    >
    > How can I get T1 to release any locks it's holding when it gets killed?


    Find and fix the bug that gets it killed. Anything else will only
    cause you more trouble later on.

    Follow-ups set to comp.unix.programmer as this is not directly related
    to the C language.

    --
    Måns Rullgård
    =?iso-8859-1?Q?M=E5ns_Rullg=E5rd?=, Oct 29, 2007
    #2
    1. Advertising

  3. CJ <> writes:
    > I've run across the following situation. I have two threads, say T1 and
    > T2 which access shared data - each locks a mutex before doing so.
    >
    > Now I have a hard-to-find bug which means that periodically T1 gets
    > killed unexpectedly. But if it holds the mutex at that point, T2 blocks
    > for ever!
    >
    > How can I get T1 to release any locks it's holding when it gets killed?


    Standard C has no threads, so comp.lang.c isn't the place to ask about this.

    I've redirected followups to just comp.unix.programmer (not that it
    will do any good), but comp.programming.threads might also be a good
    place to ask.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Oct 29, 2007
    #3
  4. CJ

    CJ Guest

    On 29 Oct 2007 at 21:05, Måns Rullgård wrote:
    > CJ <> writes:
    >
    >> Hello Friends -
    >>
    >> I've run across the following situation. I have two threads, say T1 and
    >> T2 which access shared data - each locks a mutex before doing so.
    >>
    >> Now I have a hard-to-find bug which means that periodically T1 gets
    >> killed unexpectedly. But if it holds the mutex at that point, T2 blocks
    >> for ever!
    >>
    >> How can I get T1 to release any locks it's holding when it gets killed?

    >
    > Find and fix the bug that gets it killed. Anything else will only
    > cause you more trouble later on.


    I promise you, not fixing the bug is not the result of lack of will! It
    basically comes down to some completely unmanageable and unpenetrable
    code that we have to work with. We can basically work around the bug,
    but the only problem is the dead thread keeping its locks - there must
    be a solution to that?
    CJ, Oct 29, 2007
    #4
  5. On Oct 29, 4:24 pm, CJ <> wrote:

    > I promise you, not fixing the bug is not the result of lack of will! It
    > basically comes down to some completely unmanageable and unpenetrable
    > code that we have to work with. We can basically work around the bug,
    > but the only problem is the dead thread keeping its locks - there must
    > be a solution to that?


    Run the broken code in its own process. Threads are not isolated from
    each other. There is no such thing as a "dead thread", only a crashed
    process.

    DS
    David Schwartz, Oct 30, 2007
    #5
  6. CJ

    CBFalconer Guest

    CJ wrote:
    > Måns Rullgård wrote:
    >> CJ <> writes:
    >>
    >>> I've run across the following situation. I have two threads,
    >>> say T1 and T2 which access shared data - each locks a mutex
    >>> before doing so.
    >>>
    >>> Now I have a hard-to-find bug which means that periodically T1
    >>> gets killed unexpectedly. But if it holds the mutex at that
    >>> point, T2 blocks for ever!
    >>>
    >>> How can I get T1 to release any locks it's holding when it
    >>> gets killed?

    >>
    >> Find and fix the bug that gets it killed. Anything else will
    >> only cause you more trouble later on.

    >
    > I promise you, not fixing the bug is not the result of lack of
    > will! It basically comes down to some completely unmanageable
    > and unpenetrable code that we have to work with. We can basically
    > work around the bug, but the only problem is the dead thread
    > keeping its locks - there must be a solution to that?


    I thought you had already been told this is off-topic on c.l.c,
    because standard C has no threads. You need a newsgroup that deals
    with your system, such as comp.unix.programmer.

    --
    Chuck F (cbfalconer at maineline dot net)
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net>



    --
    Posted via a free Usenet account from http://www.teranews.com
    CBFalconer, Oct 30, 2007
    #6
  7. On Oct 29, 4:24 pm, CJ <> wrote:

    > I promise you, not fixing the bug is not the result of lack of will! It
    > basically comes down to some completely unmanageable and unpenetrable
    > code that we have to work with. We can basically work around the bug,
    > but the only problem is the dead thread keeping its locks - there must
    > be a solution to that?


    Run the broken code in its own process. Threads are not isolated from
    each other. There is no such thing as a "dead thread", only a crashed
    process.

    DS
    David Schwartz, Oct 30, 2007
    #7
    1. Advertising

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. Jim Heavey

    ASPNET_wp locks my machine up

    Jim Heavey, Oct 15, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    377
    Jim Cheshire [MSFT]
    Oct 16, 2003
  2. Tom Pester

    Migrating to ADO.NET and locks

    Tom Pester, Oct 19, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    397
    Natty Gur
    Oct 20, 2003
  3. Thomas Rast

    Reclaiming (lots of) memory

    Thomas Rast, Oct 2, 2004, in forum: Python
    Replies:
    11
    Views:
    542
    Luis P Caamano
    Oct 22, 2004
  4. softwarepearls_com

    Reclaiming this group for Java enthusiasts

    softwarepearls_com, Sep 29, 2008, in forum: Java
    Replies:
    4
    Views:
    381
    Arne Vajhøj
    Oct 4, 2008
  5. Mario
    Replies:
    1
    Views:
    142
Loading...

Share This Page