|
From: Paul F. <pj...@wa...> - 2021-10-18 09:33:04
|
> Message du 18/10/21 10:41 > De : "Ryan Cai" > A : val...@li... > Copie à : > Objet : [Valgrind-developers] About the functionalities of Helgrind > > > I am Ryan Cai, coming from HK. Helgrind is a wonderful > thread error detector I have ever used. I look into the > detected errors due to the misuses of the POSIX pthreads > API and am curious what’s the difference between these two errors? > > unlocking an invalid mutex > unlocking a not-locked mutex > > I am also wondering what’s the difference between an invalid mutex > and an not-locked mutex. Thank you very much for your time! Hi Ryan When you create a mutex, it needs to be correctly initialized. >From the manpage for pthread_mutex_init there is int pthread_mutex_init(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict attr); pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; It is also possible for a correctly initialized mutex to be corrupted, for instance by an out of bounds write. You can't unlock an uninitialized or corrupt mutex - Helgrind will generate an error. A not-locked mutex is one that has been correctly initialized and then either nothing has happened to it or it has been locked and unlocked an equal number of times and in that order. Thus the lock count is zero when there is an attempt to unlock. You will get an error if you do this mutex init mutex unlock // never locked or this mutex init mutex lock mutex unlock mutex unlock // has been locked but the lock count is zero Regards Paul |