Operating Systems: Three Easy Pieces - Thread API

교재에서는 c의 POSIX을 기반으로 진행되고 있고 Python을 공부 중이므로 Python의 threading로 해당 글을 진행합니다. threading 모듈은 OS의 저수준 스레딩 기능 위에 구축된 객체 지향 API로 Unix 계얼에서는 POSIX Thread(pthreads) 라이브러리를 기반으로 동작합니다. Thread Creation 파이썬에서는 threading.Thread 객체를 만들어 스레드를 생성합니다. 핵심은 “어떤 함수를 어떤 인자로 실행할지"를 스레드 객체에 넘기고, start()로 실행을 시작하는 흐름입니다. import threading def worker(name, count): for i in range(count): print(f"[{threading.current_thread().name}] {name}: {i}") # target: 새 스레드에서 실행할 함수 # args: target 함수에 전달할 인자 튜플 t1 = threading.Thread(target=worker, args=("A", 3), name="Thread-A") t2 = threading.Thread(target=worker, args=("B", 3), name="Thread-B") t1.start() t2.start() threading.Thread(...) 호출은 내부적으로 Thread.__init__(...) 인자와 매핑이 되죠죠 ...

April 29, 2026 · 13 min · DSeung001

Operating Systems: Three Easy Pieces - Concurrency: An Introduction

Process vs Thread 멀티 스레드는 하나의 Program Counter(PC)만 갖는 단일 스레드와 달리 각 스레드가 자신만의 Program Counter(PC)와 스택(Stack) 을 가집니다. 이로 인해 멀티 프로세스와 달리 다음 차이점들이 발생합니다. ※ Program Counter(PC): 다음에 실행할 명령어의 주소를 저장하는 레지스터 하나의 프로세스에 두 개의 스레드(T1, T2)가 있다고 가정해보면, T1에서 T2로 넘어갈 때 스레드 간 컨텍스트 스위치가 일어납니다. 이 과정은 프로세스 간 컨텍스트 스위치와 비슷하게 현재 실행 상태를 저장하고 다음 실행 상태를 복원한다는 점에서 유사합니다. ...

April 28, 2026 · 14 min · DSeung001