Overview
| Artifact ID: | 9fd4152c8fc35b5e4232963366f39c3b7f75b9acadda1a1bd173439e04c19112 |
|---|---|
| Ticket: | 893f8cc5db3ba8bd6bed80ce89a0a75c6088a37c
Nested mutexes following TIP 509 |
| User & Date: | chw on 2025-09-26 16:29:41 |
Changes
- closedate changed to: "2460945.18729079"
- closer changed to: "chw"
- icomment:
Ashok, as far as I am able to remember, the problem of the initial implementation of the recursive mutexes (the POSIX variant without native recursion support) raised sooner or later the question about memory safety, consistency, or whatever we like to name it, which was you brought up by you. In the follow up additional code and complexity to the mutex implementation was added. Now the fine point is, reading https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_12 that consistence is ensured within the critical region. The reverse conclusion thus must be: if the critical region is initialized "critically" and only written "critically" the state read from outside is somewhat consistent, too. At least can it only be in two possible states in between (thread identifier being PTHREAD_NULL or not). And that fits tests of a thread identifier being not equal to some other thread identifier. And moreover does it not require accesses to be of somehow atomic or otherwise nuclear kind. My only point is, that we could have lived well with the initial implementation, if we would have added initial locks, when we initialize our mutex structure. And of course ditched the native recursive POSIX stuff in favor of our own breed due to the misfit with POSIX condition variables. So the pmutexPtr->thread value is either our pthread_self() or not. And this condition is *always* ensured when we modify it only when we hold the critical section. Even when we give up ownership by writing PTHREAD_NULL. Most of this argumentation can be translated to Win32 as well.
- login: "chw"
- mimetype: "text/plain"