[patch] Re: dlopen() and dlclose() are not MT-safe?

Kazuaki Oda kaakun at highway.ne.jp
Thu Mar 23 13:25:17 UTC 2006


Kostik Belousov wrote:
> The reasoning behind releasing the lock is to allow calls to dl*()
> functions from constructors/destructors. This is common practice
> and shall be supported. Yes, leaving the lock taken will lead to
> deadlock.
> 
> Please, try the following patch and report results. I can run (modified *)
> version of your test for some time without crash with both libpthread
> and libthr.
> 
> [* You need to allow for errors in dlopen and just continue the loop.]
> 
> Patch protects access to the list of unloading objects by bind lock,
> and marks the objects that are running finalizers to prevent
> simultaneous loading of them.
> 
> Also, it comments out code that is completely incomprehensible by my sloppy
> brain. Namely, the thread_mask_set stuff seems to allow for the thread
> to run as-is if another thread taken the lock. As result, lock is
> effectively ignored. I cannot understand purpose of this fragments.
> Hope, kan@ describe the reasons.

Thanks.  I tried your patch, and the test program did not crash any 
more.  But I needed to modify it as you say.  IMHO there are probably 
programs in the world that don't retry in case of errors in dlopen(), 
so they still have problems in such case..

--
Kazuaki Oda


More information about the freebsd-hackers mailing list