signal and STL constructors conflict causing deadlock, or - __USE _MALLOC and RedHat 8.0
Honigstein, Bat-sheva
bat-sheva.honigstein@intel.com
Thu Mar 13 12:07:00 GMT 2003
> Hi!
>
> 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
library."
>
> 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;
> alarm(1);
> }
>
> int main() {
> signal(SIGALRM, sig);
> alarm(1);
> while (1) {
> string s = "QUEUEUE";
> }
> return 0;
> }
More information about the Libstdc++
mailing list