Created
June 27, 2016 08:18
-
-
Save yremmet/a63826aeb8d22b5db43c313914a92aff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.swift | |
// test | |
// | |
// Created by enat on 27/06/16. | |
// Copyright © 2016 enat. All rights reserved. | |
// | |
import UIKit | |
class ViewController: UIViewController { | |
private let queue = dispatch_queue_create( | |
"queue", DISPATCH_QUEUE_SERIAL) | |
private let queue2 = dispatch_queue_create( | |
"queue1", DISPATCH_QUEUE_CONCURRENT) | |
private let queue3 = dispatch_queue_create( | |
"queue2", DISPATCH_QUEUE_CONCURRENT) | |
//private let lock = NSLock() | |
let group = dispatch_group_create() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
lock.lock() | |
dispatch_group_enter(self.group) | |
dispatch_async(queue, { | |
self.asyncCall("1") | |
}) | |
dispatch_group_wait(group, DISPATCH_TIME_FOREVER) | |
dispatch_group_enter(self.group) | |
dispatch_async(queue, { | |
self.asyncCall("2") | |
}) | |
dispatch_group_wait(group, DISPATCH_TIME_FOREVER) | |
dispatch_group_enter(self.group) | |
dispatch_async(queue, { | |
self.asyncCall("3") | |
}) | |
dispatch_group_wait(group, DISPATCH_TIME_FOREVER) | |
dispatch_group_enter(self.group) | |
dispatch_async(queue, { | |
self.asyncCall("4") | |
}) | |
dispatch_group_wait(group, DISPATCH_TIME_FOREVER) | |
dispatch_group_enter(self.group) | |
lock.unlock(); | |
asyncCall("Main"); | |
} | |
func asyncCall(test:String){ | |
//lock.lock() | |
print(test) | |
dispatch_async(queue2, { | |
print( test) | |
dispatch_async(self.queue3, { | |
print(test) | |
//self.lock.unlock() | |
dispatch_group_leave(self.group) | |
}) | |
}) | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment