はい
##クラス
Android | iOS |
---|---|
java.util.concurrent.CountDownLatch | DispatchSemaphore |
##例 | |
#####CountDownLatch |
public void Test() {
int max = 10;
CountDownLatch count = new CountDownLatch(max);
for (int i=0; i < max; ++i) {
new Thread() {
public void run() {
Log.d("Hoge", "count = " + i);
count.countDown();
}
}.start();
}
count.await();
Log.d("Hoge", "finish");
}
#####DispatchSemaphore
func Test() {
let max: Int = 10;
let sema: DispatchSemaphore = DispatchSemaphore(value: 0) // <- 注意
for i: Int 0..<10 {
DispatchQueue.main.async {
print("count =", i)
sema.signal()
}
}
for _ in 0..<max { sem.wait() } // <- はい
print("finish")
}
##動作確認
してない
##キーワード
排他制御
##^ν^「こうやったほうがいいよ!」
きいてないです