Summary: As per title. These test pass already because the previous thread domain was sufficient to express them. This won't necessarily be true when the whole-program analysis version comes around, because we may decide to not report on the `Threaded` elements (see domain). Reviewed By: dulmarod Differential Revision: D17930653 fbshipit-source-id: 2174f6b22master
parent
e2725029f2
commit
0a06353bce
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* 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.support.annotation.UiThread;
|
||||||
|
import android.support.annotation.WorkerThread;
|
||||||
|
|
||||||
|
class ThreadDeadlock {
|
||||||
|
Object lockA;
|
||||||
|
|
||||||
|
// methods cannot run in parallel because both are on UI thread, thus no deadlock
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
public synchronized void noParallelismAOk() {
|
||||||
|
synchronized (lockA) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
public void noParallelismBOk() {
|
||||||
|
synchronized (lockA) {
|
||||||
|
synchronized (this) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Object lockB;
|
||||||
|
|
||||||
|
// deadlock, one method on UI thread, one on Worker thread
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
public synchronized void annotatedUiThreadBad() {
|
||||||
|
synchronized (lockB) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@WorkerThread
|
||||||
|
public void annotatedWorkerThreadBad() {
|
||||||
|
synchronized (lockB) {
|
||||||
|
synchronized (this) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Object lockC;
|
||||||
|
|
||||||
|
// deadlock as above, but here assertions are used to determine thread status
|
||||||
|
|
||||||
|
public synchronized void assertOnUIThreadBad() {
|
||||||
|
OurThreadUtils.assertOnUiThread();
|
||||||
|
synchronized (lockC) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void assertOnBackgroundThreadBad() {
|
||||||
|
OurThreadUtils.assertOnBackgroundThread();
|
||||||
|
synchronized (lockC) {
|
||||||
|
synchronized (this) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Object lockD;
|
||||||
|
|
||||||
|
// deadlock as above, though less certain because the only hint of concurrency is that
|
||||||
|
// methods take locks
|
||||||
|
|
||||||
|
public synchronized void notAnnotatedBadA() {
|
||||||
|
synchronized (lockD) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void notAnnotatedBBad() {
|
||||||
|
synchronized (lockD) {
|
||||||
|
synchronized (this) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.support.annotation.UiThread;
|
|
||||||
|
|
||||||
class UIDeadlock {
|
|
||||||
Object lockA, lockB;
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
public synchronized void onUIThreadAOk() {
|
|
||||||
synchronized (lockA) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
public void onUIThreadBOk() {
|
|
||||||
synchronized (lockA) {
|
|
||||||
synchronized (this) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
public synchronized void onUIThreadBad() {
|
|
||||||
synchronized (lockB) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void notOnUIThreadBad() {
|
|
||||||
synchronized (lockB) {
|
|
||||||
synchronized (this) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in new issue