๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ“ฑ iOS Programming/Cocoa-Touch Framework

Dispatch Queue (Concurrency Control)

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