https://bugs.openldap.org/show_bug.cgi?id=9278
--- Comment #13 from Howard Chu hyc@openldap.org --- Must also note - there would still be another race condition, regardless:
When the first process destroys the mutexes, and still has the lockfile open, another process attempting to open the env during that time will see that the lockfile is locked, which it would take to mean all of the lockfile contents are still valid. Meanwhile the first process unmaps the region, and the kernel wipes out the underlying mutex structures. Then the first process closes the lockfile which releases the lock, the later process acquires the readlock and tries to use the lockfile as-is but its mutexes are no longer valid.
This race would occur regardless of what libc / libthr does since the kernel automatically GCs the underlying mutex structures as soon as the region is unmapped. It could be avoided if the kernel additionally waits to cleanup until there are no open descriptors on the file.