This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
RE: dlopen handles and multiple threads
- From: Matthew Fortune <Matthew dot Fortune at imgtec dot com>
- To: Will Newton <will dot newton at linaro dot org>
- Cc: "libc-alpha at sourceware dot org" <libc-alpha at sourceware dot org>
- Date: Thu, 3 Jul 2014 11:20:58 +0000
- Subject: RE: dlopen handles and multiple threads
- Authentication-results: sourceware.org; auth=none
- References: <6D39441BF12EF246A7ABCE6654B0235320E5E2BD at LEMAIL01 dot le dot imgtec dot org> <CANu=Dmg3YzmN71OoapNFgotgCpMGmpZcKJwJvmAKqV0ngM5h0w at mail dot gmail dot com>
Will Newton <will.newton@linaro.org> writes:
> 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?
No I have no reason to believe they are invalid. I was just hoping they
might be for a reason that I did not know! This is related to the MIPS
ABI work which is progress for transitioning O32 from FR0 to FR1.
It came to light that performing a mode switch during dlopen on one thread
would not update the mode on any other thread sharing the address space. The
mode change would be a pre-requisite of executing any code in the newly
opened library. If a different thread accesses that code in its
pre-existing mode then it would fail.
There are some possible solutions to mode switching all threads in a process
I am just trying to ensure that it is necessary before doing it.
Thanks,
Matthew