@UIApplicationMain
class AppDelegate: UIResponder,UIApplicationDelegate {
var window: UIWindow?
var product = [String]()
let condition = NSCondition()
func application(application: UIApplication,didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
NSThread.detachNewThreadSelector("consume",toTarget: self,withObject: nil)
NSThread.detachNewThreadSelector("create",withObject: nil)
return true
}
func create() {
condition.lock()
print("create a product")
product.append("*")
condition.signal()
condition.unlock()
}
func consume() {
condition.lock()
while product.count == 0 {
print("waiting for create product")
condition.wait()
}
print("consume a product")
product.removeFirst()
condition.unlock()
}