Created
May 17, 2021 08:39
-
-
Save sujinnaljin/32fa3fc4d23f4527d289b9b5373c2a22 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import UIKit | |
| class ViewController: UIViewController { | |
| let workerQueue = DispatchQueue(label: "com.sujinnaljin.worker", | |
| attributes: .concurrent) | |
| let falcon = Falcon(name: "naljin") | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| changeName() | |
| } | |
| func changeName() { | |
| for name in ["수지니", "날지니", "해동청", "보라매"] { | |
| workerQueue.async { | |
| self.falcon.name = name | |
| print("name is : \(self.falcon.name)") | |
| } | |
| } | |
| } | |
| } | |
| class Falcon { | |
| let concurrentQueue = DispatchQueue(label: "com.sujinnaljin.concurrent", | |
| attributes: .concurrent) | |
| private var _name: String | |
| var name: String { | |
| get { | |
| //읽기 - sync | |
| concurrentQueue.sync { | |
| return self._name | |
| } | |
| } | |
| set { | |
| //쓰기 - async | |
| concurrentQueue.async(flags: .barrier, execute: { | |
| self._name = newValue | |
| }) | |
| } | |
| } | |
| init(name: String) { | |
| self._name = name | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment