Do threads cooperate with Android?


#1

Hi there, do std::thread::spawn(||{}) threads cooperate nicely with android? On the jni tips page it says that I would have to use something called pthread_create (Which I’m not familiar with). Would Rust’s standard library automatically make threads on android as it does on windows, without any user intervention necessary?


#2

All unix platforms, including Android, do implement std::thread using the pthread library. Threads are never automatically created by the standard library, but crates like rayon will create a thread pool for their work.


#3

Ah, thanks for the information, last thing I’d want to do is go into debugging a threaded application on Android, when I can’t create a thread on Android. Anyway, I made a mistake on my original post, I never would have expected the standard library to create threads, what I meant is if it was as smooth a process on android as it is on windows.


#4

And the answer is: It’s as smooth a process as any other OS when using std::thread.
Android uses the same facilities as other unix-based platforms (there are several). It’s not the same OS facility as windows, because windows isn’t unix-based, but the differences are minor and are obscured by the standard library.
You shouldn’t have to worry about them unless you’re doing something very low-level and OS-specific (It’s not even enough of a concern to be mentioned in the std::thread documentation).