[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

signal and STL constructors conflict causing deadlock

From: Honigstein, Bat-sheva
Subject: signal and STL constructors conflict causing deadlock
Date: Thu, 13 Mar 2003 14:00:34 +0200


        I'm trying to create a timer, using signal (SIGALARM). In that timer
a string is allocated. At the same time the main flow is also allocating
strings. (This, of course, is a small example of a much more complex issue).
When I compile my file with g++ sigmalloc.cpp -lpthread, I get a deadlock
caused by the fact that the main flow was interrupted by the signal while in
the string constructor.

        Some research has shown that I should use -D__USE_MALLOC in
compilation. This does, indeed, solve the deadlock. However, as I tried to
compile my code on RedHat 8 I received the following error: 
        "In file included from /usr/include/c++/3.2/iostream:44,
                 from /usr/include/c++/3.2/backward/iostream.h:32,
                 from sigmalloc.cpp:7:
/usr/include/c++/3.2/i386-redhat-linux/bits/c++config.h:74:2: #error
__USE_MALLOC should only be defined within
libstdc++-v3/include/bits/c++config before full recompilation of the

        I would appreciate any advice!

        Thanks a lot!
My code:

#include <pthread.h>
#include <unistd.h>
#include <signal.h>
#include <iostream.h>
#include <string>

using namespace std;

void sig(int q)
    string s = "SIG!";
    cout << s << endl;

int main() {
    signal(SIGALRM, sig);
    while (1) {
        string s = "QUEUEUE";
    return 0;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]