dlclose

dlclose

Post by Yota Moteuch » Mon, 24 Mar 2003 00:01:29



Good Day, I want ask you a question:
I use the dynamic library perfectly but, in one case i have find a problem:
when I use a thread inside a library.
When I don't expect that all the thread are closing and I use dlclose
function I receive an Segmentation fault error.
When I expect that all the threads opens are closing dlclose function
freeze and the program start with an infinite loop.
This is strange because, if i don't call dlclose function (and close the
library with the end of the program) the function work.
How can I resolve this?
Obviously i can wait the end of the threads, but i must use dlclose
function because probably i need to load and unload a lot of libraries
before the end of the program.
Thank You for the answers.
 
 
 

dlclose

Post by M?ns Rullg? » Mon, 24 Mar 2003 01:18:37



> Good Day, I want ask you a question:
> I use the dynamic library perfectly but, in one case i have find a problem:
> when I use a thread inside a library.
> When I don't expect that all the thread are closing and I use dlclose
> function I receive an Segmentation fault error.
> When I expect that all the threads opens are closing dlclose function
> freeze and the program start with an infinite loop.
> This is strange because, if i don't call dlclose function (and close the
> library with the end of the program) the function work.
> How can I resolve this?
> Obviously i can wait the end of the threads, but i must use dlclose
> function because probably i need to load and unload a lot of libraries
> before the end of the program.

If you dlclose a library while a thread is executing code in it, you
will obviously get a SIGSEGV since the code being executed is removed
from your address map.  The solution is to wait the threads to
finish.  If the thread is started with a function inside the dlopened
libarary, you might need to call sched_yield() between pthread_join
and dlclose.  I don't know why this is required, but I had to do to
avoid occasional SIGSEGVs.

--
M?ns Rullg?rd


 
 
 

dlclose

Post by Yota Moteuch » Mon, 24 Mar 2003 01:33:45


Thank you veri much :)
 
 
 

dlclose

Post by Yota Moteuch » Mon, 24 Mar 2003 02:22:57



> Thank you very much :)

Ehr, this metod not work. If I use sched_yield it crash with another
Segmentation fault.
 
 
 

dlclose

Post by M?ns Rullg? » Mon, 24 Mar 2003 06:08:57



> Ehr, this metod not work. If I use sched_yield it crash with another
> Segmentation fault.

In that case there is still some thread executing code inside the
library, or there is a pointer to static data in the library being
used somewhere.

What is you are trying to accomplish?

--
M?ns Rullg?rd

 
 
 

dlclose

Post by Yota Moteuch » Mon, 24 Mar 2003 20:16:25



> In that case there is still some thread executing code inside the
> library,

In my test there is only one thread, and I wait this whit pthread_join

Quote:> or there is a pointer to static data in the library being
> used somewhere.

No, nothing of this.

Quote:> What is you are trying to accomplish?

A bynary that update itself. It use a library whit all the code (except the
code for the library loading) and when it must update itself it change the
library.

Excuse me if my English isn't perfect :)

 
 
 

dlclose

Post by Yota Moteuch » Mon, 24 Mar 2003 20:54:27




>> In that case there is still some thread executing code inside the
>> library,

> In my test there is only one thread, and I wait this whit pthread_join

>> or there is a pointer to static data in the library being
>> used somewhere.

> No, nothing of this.

>> What is you are trying to accomplish?

> A bynary that update itself. It use a library whit all the code (except
> the code for the library loading) and when it must update itself it change
> the library.

> Excuse me if my English isn't perfect :)

Ah, The Segmetation fault error is casual. Sometimes the application wait
in the infinite loop.
 
 
 

dlclose

Post by M?ns Rullg? » Tue, 25 Mar 2003 04:09:45



> > What is you are trying to accomplish?

> A bynary that update itself. It use a library whit all the code (except the
> code for the library loading) and when it must update itself it change the
> library.

This reminds me of a crazy project I'm playing with.  You could look
at http://tc2.sf.net.  Some of the code there might be doing similar
things.  You'll have to look in the CVS repository; the released
tarball is outdated and should be replaced.

--
M?ns Rullg?rd

 
 
 

1. Where are dlopen, dlclose, etc...

Hopefully someone can quickly point me in the right direction (you
know, kinda like telling me where to go :-). I have a program that
uses the functions dlopen, dlclose, dlerror, and dlsym that I'm trying
to port to Linux. I was overjoyed to find the file
/usr/include/dlfcn.h which contained prototypes for these functions. I
just checked and the file *does* come with the standard GCC include
tar file. Unfortunately I have no clue as to where the object code for
these functions live. Can someone tell me which library contains the
code ?

John
--
John Burton                      


(804) 865-7491 (voice)           (804) 865-1021 (fax)

2. Export Filemaker DB to use in MySQL?

3. Bugs in shared libraries (dlopen / dlclose)..

4. Linux and Linksys ether cards. what drviers to use?

5. dlclose in a multi-threaded application

6. Will Portsentry co-exist with a firewall?

7. Shared library - linux glibc6 2.1.3x, dlclose generate segmentation fault

8. Xlogin on remote system

9. dlopen and dlclose

10. Where are dlclose/dlopen?

11. dlclose broken?

12. Loading libraries run-time: dlopen, dlsym, dlclose

13. Undefined dlopen, dlclose ..