[FFmpeg-devel] default lock mechanism in libavcodec/utils.c

anshul anshul.ffmpeg at gmail.com
Thu Feb 20 06:57:34 CET 2014


On 02/20/2014 12:41 AM, Reimar Döffinger wrote:
> On Wed, Feb 19, 2014 at 05:09:15PM +0530, anshul wrote:
>> On 02/19/2014 04:46 PM, wm4 wrote:
>>> This will lead to horrible stuff like library A trying to "unload"
>>> libavcodec, while library B is still using it. You can't generally use
>>> this function correctly.
>> How does that happen "when lib A is loading and lib B is unloading"
>>
>> What I understand is follow:
>> libavcodec  has been dynamically loaded by libA and libB
>> both does not know whether libA or libB  is using libavcodec
>> and if libA change some static parameter of libavcodec then libB
>> will also see the effect.
>>
>>
>> Something I have documented that this is dangerous(unsafe) function
>> if it is called when you dont know
>> whether any thing is using libavcodec.
> And when would you ever know that? Some user on your system might be
> using a libc they for fun linked against libavcodec.
> IMHO this is an example of an API that, at least strictly speaking,
> is _impossible_ to use correctly.
> At the very least, you couldn't let anything using this API get
> into a Linux distribution unless statically linked (which in turn
> would keep it out of many distributions).
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

If any X library that is using libavcodec, but your program(process) is 
not using the library X
then you can surely state that there is no problem in unloading, because 
both of the program does
not share any section. All process have there own space and none 
interfere with other.

i did wrote some test program to verify the above statement.

library code:
static int i = 1;
void set_i(int val)
{
i = val;
}
int get_i(void)
{
return i;
}


executable:
#include <stdio.h>
#include "dlfcn.h"
void (*set_i)(int val);
int (*get_i)(void);
void (*set_i1)(int val);
int (*get_i1)(void);
int main(void)
{
int var = 0;
void *test_lib = dlopen("./libtest.so", RTLD_LAZY);
void *test_lib1 = dlopen("./libtest.so", RTLD_LAZY);

set_i = dlsym(test_lib,"set_i");
get_i = dlsym(test_lib,"get_i");
set_i1 = dlsym(test_lib,"set_i");
get_i1 = dlsym(test_lib,"get_i");


printf("enter value to set lib value:");
scanf("%d%*c",&var);
set_i(var);
getchar();
printf("val = %d\n",get_i());
// set_i1(var);
// printf("val = %d\n",get_i());
//
dlclose(test_lib);
dlclose(test_lib1);
return 0;
}



I don’t find any problem with this library when i am linking it dynamically

@Reimar Döffinger please elaborate your answer after my test your 
statement looks hypothetical
to me.

Thanks
Anshul Maheshwari



More information about the ffmpeg-devel mailing list