This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: more detailed io state; new_handler and thread safety
- From: Martin Sebor <sebor at roguewave dot com>
- To: libstdc++ at gcc dot gnu dot org
- Date: Thu, 04 Apr 2002 13:47:27 -0700
- Subject: Re: more detailed io state; new_handler and thread safety
- Organization: Rogue Wave Software, Inc.
- References: <Pine.SOL.3.91.1020404113250.25512A-100000@taarna.cygnus.com>
- Reply-to: libstdc++ at gcc dot gnu dot org
Benjamin Kosnik wrote:
>
...
>
> > 2.) I found no clear statement in my literature about
> > the thread safety of std::set_new_handler but I suspect
> > it is not thread safe. What is an approved way of having
> > several threads with each having their own new_handler
> > function set?
Unless the program replaces it, there's only one ::operator new() with
the same memory pool per process, so it doesn't seem to make sense to
have a per-thread new handler. With a replacement operator new, presumably
one that manages a pool of memory for each thread, a program can create
its own thread-safe set_new_handler function.
I think I do agree that there is a problem with the design of
std::set_new_handler(): multiple threads may want to obtain the [address
of the] current new handler, though, and that doesn't seem possible in
a thread safe way.
Regards
Martin