summaryrefslogtreecommitdiffstats
path: root/dalvik
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2011-04-05 17:21:35 -0700
committerElliott Hughes <enh@google.com>2011-04-05 17:21:35 -0700
commit9aa53337a20c6da1e026bc1b06cd3930db49349a (patch)
tree7b827196d0746ed136b1c5afd228785d0b3329d7 /dalvik
parentcc9fb8ff26275fd201d5edee5cbfee439b88f68b (diff)
downloadlibcore-9aa53337a20c6da1e026bc1b06cd3930db49349a.zip
libcore-9aa53337a20c6da1e026bc1b06cd3930db49349a.tar.gz
libcore-9aa53337a20c6da1e026bc1b06cd3930db49349a.tar.bz2
Ensure that the zygote is single-threaded before forking.
We really need to wait for the pthreads to exit. Bug: 4235038 Change-Id: Ic0ce32be80bcdc27ff8fc6ac27fa37f7c3e17e0c
Diffstat (limited to 'dalvik')
-rw-r--r--dalvik/src/main/java/dalvik/system/Zygote.java18
1 files changed, 18 insertions, 0 deletions
diff --git a/dalvik/src/main/java/dalvik/system/Zygote.java b/dalvik/src/main/java/dalvik/system/Zygote.java
index 1cdc52c..8e5b34c 100644
--- a/dalvik/src/main/java/dalvik/system/Zygote.java
+++ b/dalvik/src/main/java/dalvik/system/Zygote.java
@@ -16,6 +16,7 @@
package dalvik.system;
+import java.io.File;
import java.lang.FinalizerThread;
import java.lang.ref.ReferenceQueueThread;
@@ -51,6 +52,23 @@ public class Zygote {
private static void preFork() {
ReferenceQueueThread.stopReferenceQueue();
FinalizerThread.stopFinalizer();
+ waitUntilAllThreadsStopped();
+ }
+
+ /**
+ * We must not fork until we're single-threaded again. Wait until /proc shows we're
+ * down to just one thread.
+ */
+ private static void waitUntilAllThreadsStopped() {
+ File tasks = new File("/proc/self/task");
+ while (tasks.list().length > 1) {
+ try {
+ // Experimentally, booting and playing about with a stingray, I never saw us
+ // go round this loop more than once with a 10ms sleep.
+ Thread.sleep(10);
+ } catch (InterruptedException ignored) {
+ }
+ }
}
private static void postFork() {