effective-swift

Item 82. 스레드 안정성 수준 문서화하라

책에 소개된 내용과 iOS 관련 내용을 합하여 작성하였습니다.

📚 스레드 안전성 문서화

어떤 순서로 호출할 때 외부 동기화가 필요한지, 그리고 호출 순서와 관련 lock에 대한 내용을 명시해야합니다(조건부 안전한 클래스의 경우).

또한 클래스의 스레드 안전성은 보통 클래스의 문서화 주석에 기재하지만, 독특한 특성의 메서드라면 해당 메서드의 주석에 기재하도록 하는 것을 책에서 권장하고 있습니다.

‘Thread - Safe’ 의 의미

Thread safe code can be safely called from multiple threads or concurrent tasks without causing any problems such as data corruption or app crashes. Code that is not thread safe can only run in one context at a time. 출처: raywenderlich - Grand Central Dispatch Tutorial for Swift 4: Part 1/2

iOS에서의 Multi Thread Programming

GDC( Grand Central Dispatch )는 동시성 프로그래밍을 더 쉽고 간편하게 하기 위해 iOS에서 제공하는 도구로 Thread를 직접적으로 사용하는 것보다 GCD 사용을 권장하고 있습니다.

In the past, if an asynchronous function did not exist for what you want to do, you would have to write your own asynchronous function and create your own threads. But now, OS X and iOS provide technologies to allow you to perform any task asynchronously without having to manage the threads yourself.

One of the technologies for starting tasks asynchronously is Grand Central Dispatch (GCD). This technology takes the thread management code you would normally write in your own applications and moves that code down to the system level. All you have to do is define the tasks you want to execute and add them to an appropriate dispatch queue. GCD takes care of creating the needed threads and of scheduling your tasks to run on those threads. Because the thread management is now part of the system, GCD provides a holistic approach to task management and execution, providing better efficiency than traditional threads.

출처: Concurrency Programming Guide

iOS에서의 Multi Thread Programming 체크 리스트 ✅

참고

  1. Concurrency Programming Guide
  2. Thread Programming Guide
  3. atomic/non atomic
  4. Swift Tip: Atomic Variables
  5. iOS Developer - Value and Reference Types
  6. The Readers-Writers Problem (Swift Edition)
  7. iOS ) Concurrency Programming Guide - Concurrency and Application Design
  8. Swift의 메모리 안정성
  9. [iOS] 멀티 스레드(Multi Thread) 구현 시 고려해야될 것들
  10. Multithreading in iOS with GCD: sync and async operations made easy