I wrote:

> LIU Hao wrote:
>
>> If someone forgot to initialize their mutex like `static pthread_mutex_t 
>> mutex;`, they would have a
>> zero-initialized mutex.
>
> By taking a quick look at cond.c and rwlock.c, they seem to treat such 
> zero-initialized object as invalid and fail with EINVAL. The code in mutex.c 
> seems to be an exception.
>
>> It is, of course, no good code; but if you revert that commit, such code 
>> would be broken.
>
> I think that code which forgets to properly initialize such static object is 
> broken and really should fail to signal that code needs to be fixed.
>
> Still, if you think we should continue allowing zero-initialized 
> `pthread_mutex_t`, I'll keep this *feature* as-is.

Now that I look at `pthread_mutex_destroy`, it stores `(pthread_mutex_t)NULL`:

```
    /* Sabotage attempts to re-use the mutex before initialising it again. */
    *m = (pthread_mutex_t)NULL;
```

Treating zero-initialized `pthread_mutex_t` as invalid would also allow to 
diagnose use of a mutex after it was destroyed.

- Kirill Makurin


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

Reply via email to