[asterisk-bugs] [JIRA] (ASTERISK-24154) [patch]PTHREAD_MUTEX_INITIALIZER should not be assumed to be recursive mutex
Timo Teräs (JIRA)
noreply at issues.asterisk.org
Fri Dec 29 02:09:39 CST 2017
[ https://issues.asterisk.org/jira/browse/ASTERISK-24154?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=241201#comment-241201 ]
Timo Teräs commented on ASTERISK-24154:
---------------------------------------
Situation is still the same. musl abides to POSIX:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_init.html
"In cases where default mutex attributes are appropriate, the macro PTHREAD_MUTEX_INITIALIZER can be used to initialize mutexes. The effect shall be equivalent to dynamic initialization by a call to pthread_mutex_init() with parameter attr specified as NULL, except that no error checks are performed."
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_gettype.html
"The default value of the type attribute is PTHREAD_MUTEX_DEFAULT."
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_lock.html
"If the mutex type is PTHREAD_MUTEX_DEFAULT, the behavior of pthread_mutex_lock() may correspond to one of the three other standard mutex types as described in the table above. If it does not correspond to one of those three, the behavior is undefined for the cases marked "
The table says that DEFAULT mutex has undefined behaviour for "Relock" (=recursive locking) and "Unlock When Not Owner".
POSIX is clear that the default initializer is not reliable on making mutex a recursive one.
Perhaps the other person is using patched musl, having my patch, or not yet experienced the dead-lock problems caused by having wrong type of mutex.
I also check musl c-library source code today, and the DEFAULT mutex is still consider to be "NORMAL" mutex which cannot be used recursively.
> [patch]PTHREAD_MUTEX_INITIALIZER should not be assumed to be recursive mutex
> ----------------------------------------------------------------------------
>
> Key: ASTERISK-24154
> URL: https://issues.asterisk.org/jira/browse/ASTERISK-24154
> Project: Asterisk
> Issue Type: Bug
> Security Level: None
> Components: Core/Portability
> Affects Versions: 12.4.0
> Reporter: Timo Teräs
> Assignee: Timo Teräs
> Labels: patch
> Attachments: musl-mutex-init.patch
>
>
> Currently the build system recognizes if PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP is available, and uses it only if detected. If it is not available, PTHREAD_MUTEX_INITIALIZER is used instead. Only on Solaris and BSD, the code revers using constructors to call pthread_mutex_init with proper attributes to create recursive mutex.
> This logic is wrong. PTHREAD_MUTEX_INITIALIZER is not guaranteed to create recursive mutex. Please do that assumption only on GLIBC or other C-libraries where this is a known fact.
> Current code is broken assumably on non-GLIBC systems not explicitly listed. One notable example is musl c-library based Linux systems.
--
This message was sent by Atlassian JIRA
(v6.2#6252)
More information about the asterisk-bugs
mailing list