import Foundation let semaphore = DispatchSemaphore(value: 0) var array = [Int]() DispatchQueue.global().async { for i in 0...1000 { array.append(i) } print("end 1") } DispatchQueue.global().async { for i in 0...1000 { array.append(i) } print("end 2") } DispatchQueue.global().async { for i in 0...1000 { array.append(i) } print("end 3") } semaphore.wait()