You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
2.0 KiB

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import android.os.Binder;
import android.os.RemoteException;
class ThreadScheduling {
static Binder binder;
private static void doTransact() {
try {
binder.transact(0, null, null, 0);
} catch (RemoteException e) {
}
}
Object monitorA;
public void scheduleBlockingCallOnContendedLockBad() {
Thread t =
new Thread(
new Runnable() {
@Override
public void run() {
synchronized (monitorA) {
doTransact();
}
}
});
t.start();
Executors.runOnUiThread(
new Runnable() {
@Override
public void run() {
synchronized (monitorA) {
}
}
});
}
Object monitorB, monitorC;
public void scheduleDeadlockBad() {
Thread t =
new Thread(
new Runnable() {
@Override
public void run() {
synchronized (monitorB) {
synchronized (monitorC) {
}
}
}
});
t.start();
Executors.runOnUiThread(
new Runnable() {
@Override
public void run() {
synchronized (monitorC) {
synchronized (monitorB) {
}
}
}
});
}
Object monitorD;
class BadThread extends Thread {
@Override
public void run() {
synchronized (monitorD) {
doTransact();
}
}
}
public void scheduleBlockingCallOnContendedLockViaInheritanceBad() {
Thread t = new BadThread();
t.start();
Executors.runOnUiThread(
new Runnable() {
@Override
public void run() {
synchronized (monitorD) {
}
}
});
}
}