🗃️ 이전 글
[CS] 프로세스와 스레드 딥다이브 - 3. 실행, Context switch??
🗃️ 이전 글 [CS] 프로세스와 스레드 딥다이브 - 2. 프로세스의 구조??🗃️ 이전 글 [CS] 프로세스와 스레드 딥다이브 - 1. 딥다이브 전 기초지식🧐 학습 계기이번에 스터디를 진행하면서 운영
swift-library.tistory.com
🧵 멀티스레드 프로세스
많은 개발자들을 괴롭히고(?) 있는 스레드! 멀티 프로세싱은 Context switching을 통해서 os에서 관리한다. 하지만 각 프로세스 안에서도 Task관리... 해야겠지?
기존 전통적인 프로세스는 single-threaded process이였지만, 현대에 와서는 multithreaded process로 발전했다.
A thread is a basic unit of CPU utilization; it comprises a thread ID, a program counter (PC), a register set, and a stack. It shares with other threads belonging to the same process its code section, data section, and other operating-system resources, such as open files and signals. A traditional process has a single thread of control. If a process has multiple threads of control, it can perform more than one task at a time. Figure 4.1 illustrates the difference between a traditional single-threaded process and a multithreaded process.
위를 해석해 본다면, 스레드는 같은 프로세스에 있고, 코드, 데이터, 리소스를 공유한다.
이 뜻은 Context switching에 드는 pure overhead가 적게 든다. 효과적으로 여러가지 작업들을 번갈아 가며 처리할 수 있다. 그림에 registers, pc가 있다는 건 TCB가 있다는 뜻으로 생각해서 추가로 찾아보았다.
💿 TCB (Thread Control Block)
Thread control block - Wikipedia
From Wikipedia, the free encyclopedia Thread Control Block (TCB) is a data structure in an operating system kernel that contains thread-specific information needed to manage the thread.[1] The TCB is "the manifestation of a thread in an operating system."
en.wikipedia.org
위키백과에 아주 빈약하게 존재해있다. 🥲 어디서 자료를 찾아야 하는 것인가...
- Thread Identifier: Unique id (tid) is assigned to every new thread
- Stack pointer: Points to thread's stack in the process
- Program counter: Points to the current program instruction of the thread
- State of the thread (running, ready, waiting, start, done)
- Thread's register values
- Pointer to the Process control block (PCB) of the process that the thread lives on
위의 항목에 해당되는 값들을 가지고 있다고 한다. 결국 Thread도 Process와 비슷하게 Control Block으로 관리가 된다는 것을 알 수 있었다.
📈 암달의 법칙
공룡책에서도 암달의 법칙을 소개해주고 있다.
암달의 법칙을 이 책은 이렇게 해석했는데, 결국 직렬적으로 아무리 코어가 늘더라도 직렬적으로 수행해야 하는 작업의 비율이 높을 수록 속도 향상에는 한계가 있다는 것이다. 아무리 처리를 잘해도 결국 직렬적으로 처리해야 하는 작업의 비율을 줄이는 것이 중요하다는 뜻으로 해석 할 수도 있다.
🤔 iOS 앱에서 멀티 프로세싱이 가능한가?
우선 macOS부터 Deprecated가 된 것을 보면... 내 수준에서는 확실히 불가능 한것이 맞다... 😅 사실 당장 멀티스레딩도 벅차다.
🧑🏻💻: 스레드는 뭔가요?
🐣: 스레드는 한 프로세스 안에서 text, data, heap 자원을 공유하면서 독립적 stack을 가진 작업 단위입니다. 메모리 정보를 전환할 필요가 없기 때문에 스레드의 전환 속도가 프로세스 전환 속도보다 빠릅니다.
'→ Computer Science' 카테고리의 다른 글
[CS] 데이터의 전송 (0) | 2025.02.10 |
---|---|
[CS] 정보단위 (0) | 2025.01.31 |
[CS] 프로세스와 스레드 딥다이브 - 3. 실행, Context switch?? (0) | 2025.01.18 |
[CS] 프로세스와 스레드 딥다이브 - 2. 프로세스의 구조?? (1) | 2025.01.18 |
[CS] 프로세스와 스레드 딥다이브 - 1. 딥다이브 전 기초지식 (0) | 2025.01.18 |