Grand Central Dispatch (GCD): low-level API for managing concurrent operations. (Schedules threads in shared pool)
= GCD is built on top of threads and manages a shared thread pool + decides which thread to execute them on.
& GCD decides how much parallelism it requires based on the system and available system resources.
* Doesn't work well in Simulators (CIDetector-x)
* Attempting to synchronously execute a work item on the main queue(UI-Update)=Serial results in Deadlock.
์ง๋ ฌ (Serial Queue-FIFO) / *๋์ (Concurrent Queue)
* ๋์์ฑ ์ ์ด (Concurrency Control) - ํ๋ก์ธ์ค/์ฐ๋ ๋
- parallelism (๋ณ๋ ฌ์ฑ - ์ค์ CPU ์ฝ์ด์ ์ํฅ ๋ฐ์): ์ค์ ๋์ ์์ (Execution) - ๋ฌผ๋ฆฌ์ ๋์์ฑ
- Time Slicing (์๊ฐ ๋ถ๋ฐฐํ๋ฉด์, ๋ฌธ๋งฅ ๊ตํ): ๋์ ์์ ์ฒ๋ผ ๋ณด์ด๋๋ก Context Switching (Structure) - ๋ ผ๋ฆฌ์ ๋์์ฑ
โป ํท๊ฐ๋ฆฌ๊ธฐ ์ฌ์ด, Seperate Concept
# ๋์์ฑ/๋ณ๋ ฌ์ฑ - ํ ์คํฌ ์ค์ผ์ค๋ง
# ๋๊ธฐ/๋น๋๊ธฐ - ์ ํด์ง ํ ์คํฌ ํ ๋ด์์, ์คํ ๋ฐฉ์ ์ค์ (ํด๋น ํ ์คํฌ ์๋ต์ ๊น์ง<await>, ๋ค๋ฅธ ํ ์คํฌ ์ฒ๋ฆฌ ๊ฐ๋ฅ)
- CPU Core (Single/Multi-Process)
ใด In a process, Multi-Thread (Managing Queue<Concurrent/Serial> - Add+Task / Remove-Task)
# GCD์์ ์ ๊ณตํ๋ Queue Type
- Main Queue: Serial Queue, Operated in Main Thread (UI-Flow_Life Cycle).
- Global Queue: Priority (high, default, low, background) Concurrent Queue
+ QoS Options ์ค์ ๊ฐ๋ฅ - User-interactive, User-initiated, Utility, Background
- Custom Queue: Serial or Concurrent Custom Queue
(But, The requests in these queues actually end up in one of the global queues.)
+ Call Functions in Queue <Synchronous/Asynchronous>
โจ ์ฆ, ์ด 4 ์ข ๋ฅ: DispatchQueue - Concurrent/Serial + Async/Sync
To be continued..
+ Await (์์ฒญ/์๋ต ๋๊ธฐ)
+ iOS_Life Cycle & ARC
[References]
https://www.kodeco.com/28540615-grand-central-dispatch-tutorial-for-swift-5-part-1-2
https://developer.apple.com/documentation/DISPATCH
https://docs.swift.org/swift-book/documentation/the-swift-programming-language/concurrency
'๐ฑ iOS Programming > Frameworks & Libraries' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Swift] Collection Types & Higher Order Functions (0) | 2024.09.30 |
---|