Medo42
Medo42

Reputation: 3821

Shared native libraries on android and libc thread safety

I am new to Android development (and not an expert on C/C++ either), but find myself working on a native shared library written in C that is supposed to be used (among other platforms) by an Android app.

Now, I started thinking about thread safety, and determined that my lib is currently not thread safe (uses static/global variables). No problem, I will simply use it from just one thread.

Here is where my actual question starts. From some posts on the internet (e.g. on Launchpad, it seems that some parts of the bionic libc (in particular, stdio) are not thread safe either, at least in some Android releases (we still target pre-3.0). Now the question is, will other native libraries used in this app/process share the same libc instance, causing thread safety issues, or does every shared library get its own libc instance?

In case libc is shared between all shared libs, where can I find information on which parts of it are thread safe and which aren't? Do I have to use all my native libs from the same thread to be on the safe side?

Edit: Updating with my current understanding: The bionic libc is supposed to be thread safe entirely, and the issue shown above is an isolated bug that will not happen in most situations (like many MT bugs). The question stands, but my best guess is that the entire process shares the same libc instance. I'll try to test this later.

Upvotes: 3

Views: 535

Answers (0)

Related Questions