public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/107857] recursive_mutex misses destructor if non-function call initialization is used
Date: Fri, 15 Dec 2023 12:17:08 +0000	[thread overview]
Message-ID: <bug-107857-4-jCXYpiCDUc@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-107857-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107857

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Could you please run this and paste the output here?

#include <mutex>
#include <shared_mutex>
#include <condition_variable>
#include <iostream>
#include <processthreadsapi.h>

unsigned long
muh_handles()
{
    unsigned long n = 0;
    if (GetProcessHandleCount(GetCurrentProcess(), &n))
      return n;
    throw;
}

int main()
{
  int start, end;

  start = muh_handles();
  {
    std::mutex m;
    m.lock();
    m.unlock();
  }
  end = muh_handles();
  std::cout << "Handles leaked by std::mutex: " << (end - start) << std::endl;

  start = end;
  {
    std::recursive_mutex m;
    m.lock();
    m.unlock();
  }
  end = muh_handles();
  std::cout << "Handles leaked by std::recursive_mutex: " << (end - start) <<
std::endl;

  start = end;
  {
    std::timed_mutex m;
    m.lock();
    m.unlock();
  }
  end = muh_handles();
  std::cout << "Handles leaked by std::timed_mutex: " << (end - start) <<
std::endl;

  start = end;
  {
    std::recursive_timed_mutex m;
    m.lock();
    m.unlock();
  }
  end = muh_handles();
  std::cout << "Handles leaked by std::recursive_timed_mutex: " << (end -
start) << std::endl;

  start = end;
  {
    std::shared_mutex m;
    m.lock();
    m.unlock();
  }
  end = muh_handles();
  std::cout << "Handles leaked by std::shared_mutex: " << (end - start) <<
std::endl;

  start = end;
  {
    std::shared_timed_mutex m;
    m.lock();
    m.unlock();
  }
  end = muh_handles();
  std::cout << "Handles leaked by std::shared_timed_mutex: " << (end - start)
<< std::endl;

  start = end;
  {
    std::mutex m;
    std::unique_lock<std::mutex> l(m);
    std::condition_variable cv;
    cv.wait_for(l, std::chrono::seconds(0));
  }
  end = muh_handles();
  std::cout << "Handles leaked by std::condition_variable: " << (end - start)
<< std::endl;
}

I tried to check it on Wine, but the Windows function isn't implemented:
012c:fixme:process:NtQueryInformationProcess ProcessHandleCount
(0xffffffffffffffff,0x7ffffe2ffdfc,0x00000004,(nil)) stub

  reply	other threads:[~2023-12-15 12:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-24  9:41 [Bug libstdc++/107857] New: " pg.ensiie at gmail dot com
2023-12-15 12:17 ` redi at gcc dot gnu.org [this message]
2023-12-15 12:31 ` [Bug libstdc++/107857] " redi at gcc dot gnu.org
2023-12-15 12:32 ` redi at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-107857-4-jCXYpiCDUc@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).