std::mutex bug: Windows handle growth
Noel Grandin
noelgrandin@gmail.com
Tue Mar 17 14:37:32 GMT 2026
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.
More information about the Cygwin
mailing list