Re: std::mutex bug: Windows handle growth

Noel Grandin via Cygwin <[email protected]>
Newsgroups gmane.os.cygwin
Message-ID <[email protected]>

On 3/17/2026 4:08 PM, Corinna Vinschen via Cygwin wrote:
> On Mar 17 09:06, Noel Grandin via Cygwin wrote:
> No, checking trylock() is correct.  pthread_mutex_destroy() must not
> destroy a busy mutex.  trylock() returns != 0 if the lock is busy.
> 

Aha! I misread that code.

> Given the implementation of std::mutex is based on pthread_mutex,
> Frank's code is wrong, or at least somewhat borderline.  The mutex
> should first be unlocked before leaving do_something().
> 

std::lock_guard will unlock in its destructor, so it should unlock before leaving do_something().

Regards, Noel Grandin.

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.