Signal handling in C++

Discussion in 'C++' started by E.T. Grey, Oct 14, 2005.

  1. E.T. Grey

    E.T. Grey Guest

    Hi,

    I am trying to handle signals (SIGTERM, SIGILL and SIGABRT) in my C++ code.

    I have member functions defined as follows:

    /* Hack to allow signal handling */
    void BaseProcess::proc_death_catcher( int not_used ) {
    proc_terminate() ;
    }


    In my initialization code for class BaseProcess, I set up the handlers
    as follows:

    signal(SIGTERM, proc_death_catcher);
    signal(SIGILL, proc_death_catcher);
    signal(SIGABRT, proc_death_catcher);


    When I compile the code, I get the following error:

    error C2664: 'signal' : cannot convert parameter 2 from 'void (int)' to
    'void (__cdecl *)(int)'


    The error appears to suggests that the calling convention is different
    from what was expected.

    If this inference is correct, it leads to a number of other questions:

    1). What is the recommended way (i.e. best practise) to call a C
    callback function from a class?

    2). Do different instances of the class call into the same code (ala
    static method) - or is the same copy of the callback used for all
    instances of the class?

    3). Is the answer to question 2 was that the same copy is used - then
    this approach (calling C callbacks from C++ classes) is likely to be
    thread *unsafe*. True?
    E.T. Grey, Oct 14, 2005
    #1
    1. Advertising

  2. E.T. Grey

    Rolf Magnus Guest

    E.T. Grey wrote:

    > 1). What is the recommended way (i.e. best practise) to call a C
    > callback function from a class?


    See the FAQ to this newsgroup. Look at section 33 and especially question
    33.2 "How do I pass a pointer-to-member-function to a signal handler, X
    event callback, system call that starts a thread/task, etc?"
    Rolf Magnus, Oct 14, 2005
    #2
    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. Michael Pronath
    Replies:
    1
    Views:
    1,166
    Diez B. Roggisch
    Jan 3, 2005
  2. Jack Orenstein

    threading.Thread vs. signal.signal

    Jack Orenstein, Sep 18, 2005, in forum: Python
    Replies:
    0
    Views:
    463
    Jack Orenstein
    Sep 18, 2005
  3. Weng Tianxiang
    Replies:
    2
    Views:
    658
    Jonathan Bromley
    Jan 30, 2007
  4. Nicolas Moreau
    Replies:
    9
    Views:
    3,138
  5. Peter
    Replies:
    34
    Views:
    1,935
    James Kanze
    Oct 17, 2009
Loading...

Share This Page