Maxim Sobolev wrote:
> This scenario doesn't look as a legitimate way to do things for me.
> Let's inspect what will happen when you are unloading a PIC module,
> which has one or more threads running. There are two possibilities:
> either thread scheduler (libc_r) was linked with the program itself
> and therefore loaded with it, or it was linked with PIC module and
> loaded along with that module. In the first case, after you have
> dlclose'd the PIC module, dynamic linker will unmap module's code from
> memory, but the thread scheduler will remain running and on the next
> attempt to pass control to the thread in your PIC module will probably
> get SIGBUS due to the fact that code is no longer mapped. In the
> second case, you'll unload module along with thread scheduler, but
> thread-scheduling signals setup will remain in place, so that shortly
> you will get the same SIGBUS, when the kernel will be trying to
> delivery signal to no longer mapper region.

Unless you have a single exported API from the .so that takes a
single request, and does simultaneous lookups.

The result will be two inactive threads hanging on a condition
variable which will never come true, because the function which
makes it true in order to trigger the parallel lookup has been
unloaded.

Basically, a sleep is a sleep, and it doesn't matter if the code
that caused it is there any more or not, if you never get a
wakeup.

To use an analogy, it doesn't matter if the SIGHUP handler will
cause a core dump, if you never get a SIGHUP, does it?


> In either case, you will get the problem much more serious than memory
> leak.

Assuming, incorrectly, that you are talking to the threads
directly, rather than to a proxy function.  The calling
program need not be threaded or support threads.


> > The assumption (which is potentially wrong) is that the program
> > will correctly shut down all its threads, when in fact it was a
> > module not under the programs control that created and used the
> > threads.
> 
> I do not quite agree. In such case, the module should probably have
> destructor function, either placed into the fini section, or to be
> explicitly called by the program before dlclose().

Uh, that's exactly the argument I was making: use a .fini section
to clean up the per thread memory allocations.
8-).

-- Terry

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to