在 2026-9-25 11:19, Kirill Makurin 写道:
0004.txt

+    case WAIT_FAILED:;
+      DWORD errorCode = GetLastError ();
+
+      /**
+       * Recursive lock count has been exceeded.
+       */
+      if (errorCode == ERROR_MUTANT_LIMIT_EXCEEDED) {
+        error_code = EAGAIN;
+        break;
+      }

There's a superfluous semicolon after `case WAIT_FAILED:`.

The `default` label below jumps pass the initialization of `errorCode`; if this 
was c++, it would be a
compiler error. Perhaps it's not necessary to introduce a local variable here. 
You can just do
`GetLastError () == ERROR_MUTANT_LIMIT_EXCEEDED`.

Would you prefer me to update this or you're ok with keeping it as is?

I'd suggest you use `GetLastError () == ERROR_MUTANT_LIMIT_EXCEEDED` or move `DWORD errorCode` out of the switch statement. At my first glance this really looked like a syntax error, but later I realized that C might be more permissive.




+      if (unlikely (InterlockedCompareExchange (&mutex->State, Inconsistent, 
OwnerDied) == OwnerDied)) {
+        error_code = EOWNERDEAD;
+      }

If `WinpthreadsRobustMutexTimedLock()` returns `OwnerDied`, the state should 
already be `Inconsistent`,
so this CAS will never succeed?

I looked over code once again and I think we can remove `OwnerDied` logic for error checking but not recursive mutexes. OTOH, I think consistently using `OwnerDied` for all robust mutexes makes general logic easier to follow.

Your comments say

   /**
    * State protected by the mutex is inconsistent.
    *
    * This state is set by `pthread_mutex_unlock` when it detects that mutex
    * it tries to unlock was abandoned; the mutex becomes unlocked.
    *
    * The next thread to gain ownership of the mutex will upgrade this state
    * to `Inconsistent`.
    */
   OwnerDied,


I think this state doesn't have to exist. The scenario where a thread calls `pthread_mutex_unlock()` and the owner no longer exists is exactly that the thread which calls `pthread_mutex_unlock()` isn't the owner, and under such circumstance `pthread_mutex_unlock()` should fail with `EPERM`.


--
Best regards,
LIU Hao

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to