This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: dlopen handles and multiple threads
- From: Will Newton <will dot newton at linaro dot org>
- To: Matthew Fortune <Matthew dot Fortune at imgtec dot com>
- Cc: "libc-alpha at sourceware dot org" <libc-alpha at sourceware dot org>
- Date: Thu, 3 Jul 2014 11:32:21 +0100
- Subject: Re: dlopen handles and multiple threads
- Authentication-results: sourceware.org; auth=none
- References: <6D39441BF12EF246A7ABCE6654B0235320E5E2BD at LEMAIL01 dot le dot imgtec dot org>
On 3 July 2014 11:22, Matthew Fortune <Matthew.Fortune@imgtec.com> wrote:
> Hi all,
>
> Can anyone tell me with confidence whether either of the following scenarios are valid relating to sharing code between threads:
>
> == Scenario 1 ==
> I have two threads running.
> Thread 1 dlopens a library which is not already loaded
> Thread 1 places the handle to this library into a global variable
> Thread 1 notifies thread 2 that the handle is available (by whatever mechanism)
> Thread 2 performs a dlsym on the handle to find a function
> Thread 2 executes the function
>
> == Scenario 2 ==
> I have two threads running.
> Thread 1 dlopens a library which is not already loaded
> Thread 1 performs a dlsym on that handle to find a function
> The function pointer is stored in a global variable
> Thread 1 notifies thread 2 that the function pointer is available (by whatever mechanism)
> Thread 2 executes the function
>
> I believe the answer is that they are both perfectly valid, but I have reason to hope that at least scenario 2 is invalid.
>
> I am aware/think that the following scenario is valid:
>
> == Scenario 3 ==
> I have two threads running.
> Thread 1 dlopens a library which is not already loaded
> Thread 2 dlopens the same library and gets given a handle to the already loaded library
> Thread 2 performs a dlsym on the handle to find a function
> Thread 2 executes the function
I believe all three are valid assuming the handle/function pointer is
safely passed between the threads. Is there a reason you believe they
may not be valid?
--
Will Newton
Toolchain Working Group, Linaro