LIU Hao wrote:
> 在 2026-9-22 11:03, Kirill Makurin 写道:
>> Hello,
>>
>> These are the final mutex changes for now. We are still missing support for
>> a few POSIX realtime
>> extensions, but IMO it is not a big issue for majority of the users. Maybe
>> we can consider adding support
>> for them in a long run, perhaps after fixing existing issue.
>>
> Thanks. These mostly look good to me, except
>
>
>> +static int WinpthreadsRecursiveRobustMutexLock (WinpthreadsMutex *wMutex,
>> const struct _timespec64 *waitUntil) {
>> + WinpthreadsRecursiveRobustMutex *mutex = &wMutex->RecursiveRobustMutex;
>> +
>> + /**
>> + * The pthread_mutex_lock() function shall fail if:
>> + *
>> + * [ENOTRECOVERABLE]
>> + * The state protected by the mutex is not recoverable.
>> + */
>> + if (unlikely (mutex->State == Unrecoverable)) {
>> + return ENOTRECOVERABLE;
>> + }
>> +
>> + DWORD threadId = GetCurrentThreadId ();
>> +
>> + if (mutex->Owner == threadId) {
>
> As a robust mutex specifically handles the case where the owner thread no
> longer exists, `mutex->Owner`
> might be recycled and reused for a different thread.
Hm, you're right. Stored thread ID is used for the following:
1. Ownership check in `pthread_mutex_unlock`; using `ReleaseMutex` alone would
be sufficient as it fails if calling thread does not own the mutex.
2. Avoid recursive locking for error-checking mutexes (fails with `EDEADLK`).
3. Handle lock count in user mode for recursive mutexes.
We really only need it for case 2. Is there a way to check whether calling
thread owns the mutex without recursively locking it?
> Because a Windows Mutex object is recursive itself, it's probably not
> necessary record this information
> in user mode?
Yes, we can do this. My idea was that handling lock count in user mode may be a
little faster: we avoid extra calls to `WaitForSingleObject` and `ReleaseMutex`
on recursive lock/unlock. I'll go with your judgment on this.
- Kirill Makurin
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public