>> On 6 Oct 2016, at 13:43, Mateusz Jemielity <m.jemiel...@is-wireless.com> wrote: >> >> I'm using valgrind built from SVN, r16025. I encountered helgrind >> complaining about invalid argument used with pthread_rwlock_destroy, >> for variable initialized with PTHREAD_RWLOCK_INITIALIZER. Is this a known thing? >> Am I doing something wrong? I searched the mailing list archives on >> https://sourceforge.net/p/valgrind/mailman/valgrind-users/, but >> couldn't find anything. I'm asking because I think pthreads allows me >> to destroy rwlock initialized that way. >> >> I reproduced this with minimal test case on Ubuntu 14.04: >> $ lsb_release -a >> No LSB modules are available. >> Distributor ID:IDUbuntu >> Description:DescriptionUbuntu 14.04.5 LTS >> Release:Release14.04 >> Codename:Codenametrusty >> $ cat pthread_rwlock_destroy.c >> # define _POSIX_C_SOURCE 20161006L >> >> #include <assert.h> >> #include <pthread.h> >> >> int main(void) >> { >> pthread_rwlock_t l = PTHREAD_RWLOCK_INITIALIZER; >> assert(0 == pthread_rwlock_destroy(&l)); return 0; } > >According to the man page: > >> The pthread_rwlock_destroy() function is used to destroy a read/write lock previously created with pthread_rwlock_init(). > >You did not create the lock with pthread_rwload_init() - you used a static initialisation. Therefore my understanding is that you do not need to (and should not) call pthread_rwlock_destroy(). > >-- >Alex Bligh > Docs at http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_rwlock_des troy.html say:
In cases where default read-write lock attributes are appropriate, the macro PTHREAD_RWLOCK_INITIALIZER can be used to initialize read-write locks. The effect shall be equivalent to dynamic initialization by a call to pthread_rwlock_init() with the attr parameter specified as NULL, except that no error checks are performed. The effects are equivalent to pthread_rwlock_init, thus in my opinion they require pthread_rwlock_destroy. The internals of rwlock are opaque to me and I don't know what resources are used (especially on different systems and implementations), so I should cleanly free them just in case. I know it's not common usecase to do something like that. In my scenario I want to replace rwlock created using static initializer with another one that uses custom attributes. - Mateusz ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________ Valgrind-users mailing list Valgrind-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/valgrind-users