[Bug libstdc++/46455] New: shared_ptr consuming too many semaphores on Windows

internet at 123gen dot com gcc-bugzilla@gcc.gnu.org
Fri Nov 12 19:45:00 GMT 2010


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46455

           Summary: shared_ptr consuming too many semaphores on Windows
           Product: gcc
           Version: 4.5.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: internet@123gen.com


Created attachment 22383
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22383
test case

hello,

i have just hit a bug in the implementation of shared_ptr in GCC 4.5 on
Windows. the bug wasn't present in GCC 4.4.
the bug is also specific to libstdc++: when using boost or MSVC, there is no
problem.

basically, any creation of a shared_ptr increases the amount of semaphores used
by the process. this can be viewed by running the Task Manager and looking into
the "Handles" column. the semaphores are never released and the count therefore
keeps increasing without rest.

the following simple prog shows it:
int main() {
    int n=0;
    while (++n < 100) {
        //shared_ptr<string> x = make_shared<string>("test");
        shared_ptr<string> x(new string("test"));
        Sleep(100);
    }
    return 0;
}
(using either make_shared or the constructor doesn't make a difference.)

when running it, you will notice a steady increase of the amount of handles,
reaching more than 100 handles after 10 seconds.
compile the same prog with MSVC or GCC 4.4 and notice that the amount of
handles doesn't grow.
of course, for this simple example, it is inoffensive, but programs that make a
more important use of shared_ptr can quickly run out of available handles and
crash in unexpected ways.

for reference, the whole discussion is on
<https://bugs.launchpad.net/dcplusplus/+bug/654040>.



More information about the Gcc-bugs mailing list