This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
dlopen handles and multiple threads
- From: Matthew Fortune <Matthew dot Fortune at imgtec dot com>
- To: "libc-alpha at sourceware dot org" <libc-alpha at sourceware dot org>
- Date: Thu, 3 Jul 2014 10:22:13 +0000
- Subject: dlopen handles and multiple threads
- Authentication-results: sourceware.org; auth=none
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
Thanks,
Matthew