sigaction, muxex, condition variable

Discussion in 'C++' started by Mike - EMAIL IGNORED, Aug 8, 2007.

  1. In a Posix compliant multi-threaded C++ program,
    I would like to use sigaction() to catch SIGTERM,
    and from my signal handler, lock a mutex, and
    broadcast a condition variable. Is this ok?

    Thanks,
    Mike.
     
    Mike - EMAIL IGNORED, Aug 8, 2007
    #1
    1. Advertisements

  2. Mike - EMAIL IGNORED wrote:
    > In a Posix compliant multi-threaded C++ program,
    > I would like to use sigaction() to catch SIGTERM,
    > and from my signal handler, lock a mutex, and
    > broadcast a condition variable. Is this ok?


    You might be better off asking in a Posix newsgroup.
     
    Victor Bazarov, Aug 8, 2007
    #2
    1. Advertisements

  3. On Wed, 08 Aug 2007 18:12:07 -0400, Victor Bazarov wrote:

    > Mike - EMAIL IGNORED wrote:
    >> In a Posix compliant multi-threaded C++ program,
    >> I would like to use sigaction() to catch SIGTERM,
    >> and from my signal handler, lock a mutex, and
    >> broadcast a condition variable. Is this ok?

    >
    > You might be better off asking in a Posix newsgroup.


    Can you suggest a newsgroup?
     
    Mike - EMAIL IGNORED, Aug 9, 2007
    #3
  4. Mike - EMAIL IGNORED wrote:
    > On Wed, 08 Aug 2007 18:12:07 -0400, Victor Bazarov wrote:
    >
    >> Mike - EMAIL IGNORED wrote:
    >>> In a Posix compliant multi-threaded C++ program,
    >>> I would like to use sigaction() to catch SIGTERM,
    >>> and from my signal handler, lock a mutex, and
    >>> broadcast a condition variable. Is this ok?

    >>
    >> You might be better off asking in a Posix newsgroup.

    >
    > Can you suggest a newsgroup?


    One with "posix" in its name, perhaps? Or maybe one
    dedicated to your OS...
     
    Victor Bazarov, Aug 9, 2007
    #4
  5. Mike - EMAIL IGNORED

    James Kanze Guest

    On Aug 9, 12:12 am, "Victor Bazarov" <> wrote:
    > Mike - EMAIL IGNORED wrote:


    > > In a Posix compliant multi-threaded C++ program,
    > > I would like to use sigaction() to catch SIGTERM,
    > > and from my signal handler, lock a mutex, and
    > > broadcast a condition variable. Is this ok?


    > You might be better off asking in a Posix newsgroup.


    You're probably right, but there are two C++ questions hidden in
    there. The answer to the first is, of course, he can only call
    these functions from C++ if the system has taken the necessary
    steps so that they will show up as `extern "C"' when included
    from a C++ program. (All the systems I know have, but you never
    know.) The answer to the second is a bit more direct: according
    to the C standard (and this part of the C standard has been
    explicitly included by reference in the C++ standard): "If the
    signal occurs other than as the result of calling the abort or
    raise function, the behavior is undefined if the signal handler
    refers to any object with static storage duration other than by
    assigning a value to an object declared as volatile
    sig_atomic_t, or the signal handler calls any function in the
    standard library other than the abort function, or the signal
    function with the first argument equal to the signal number
    corresponding to the signal that caused the invocation of the
    handler." Of course, an implementation may define any undefined
    behavior, and Posix does, in fact, define a few additional
    things you can do in a signal handler.

    There's also a more general programming question involved, more
    appropriate to comp.threads than any system specific group. But
    the answer is obvious: any attempt to lock a mutex (or acquire a
    semaphore, or anything else) from an asynchronous signal
    guarantees a potential deadlock. (FWIW: under Posix, you do not
    normally use signal handlers in multithreaded code. Posix has
    other ways of handling this, that do, or at least can be made to
    work.)

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Aug 9, 2007
    #5
  6. Mike - EMAIL IGNORED

    joe Guest

    On Aug 8, 8:21 pm, Mike - EMAIL IGNORED <>
    wrote:
    > On Wed, 08 Aug 2007 18:12:07 -0400, Victor Bazarov wrote:
    > > Mike - EMAIL IGNORED wrote:
    > >> In a Posix compliant multi-threaded C++ program,
    > >> I would like to use sigaction() to catch SIGTERM,
    > >> and from my signal handler, lock a mutex, and
    > >> broadcast a condition variable. Is this ok?

    >
    > > You might be better off asking in a Posix newsgroup.

    >
    > Can you suggest a newsgroup?


    I would consider asking in comp.programming.threads. They deal with
    threading issues in many OSs.

    joe
     
    joe, Aug 9, 2007
    #6
    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. -
    Replies:
    12
    Views:
    743
    Remon van Vliet
    Jun 15, 2005
  2. Alexandre
    Replies:
    1
    Views:
    3,999
    Eric Sosman
    Apr 5, 2004
  3. Neal Becker

    sigaction?

    Neal Becker, Nov 4, 2010, in forum: Python
    Replies:
    1
    Views:
    331
    Lawrence D'Oliveiro
    Nov 7, 2010
  4. Bill W.
    Replies:
    13
    Views:
    334
    Phillip Gawlowski
    May 9, 2011
  5. Replies:
    4
    Views:
    308
Loading...

Share This Page