Assembly Language & x86 Low-Level Systems Programming · 강의

커널 공간의 동기화와 동시성

스핀락, 뮤텍스, 원자적 연산을 사용하고 인터럽트 컨텍스트와 프로세스 컨텍스트의 차이를 이해하며 커널의 공유 데이터를 안전하게 관리합니다.

레슨 4/413개 단계

커널 공간의 동기화와 동시성은(는) CoddyKit의 무료 Assembly Language & x86 Low-Level Systems Programming 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Assembly Language & x86 Low-Level Systems Programming 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Assembly Language & x86 Low-Level Systems Programming 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

The Concurrency Problem

Kernel code runs in a brutally concurrent environment: multiple CPUs, preemptible threads, and interrupts that fire anytime. Unprotected shared data leads to race conditions and corruption.

Process vs Interrupt Context

Kernel code runs in two contexts:

  • Process context: on behalf of a syscall; can sleep
  • Interrupt context: handling hardware; must NOT sleep

The context dictates which locking primitive is legal.

Atomic Operations

The simplest protection is an atomic operation that completes in a single uninterruptible step. The kernel offers types like atomic_t with helpers that map to lock-prefixed x86 instructions.

atomic_t counter = ATOMIC_INIT(0);
atomic_inc(&counter);
int v = atomic_read(&counter);

How Atomics Work in Hardware

On x86 the lock prefix makes a read-modify-write instruction atomic across cores by asserting a cache-line lock.

lock inc dword [counter]   ; atomic increment across CPUs

Spinlocks

A spinlock busy-waits until the lock is free. It never sleeps, so it is the only choice in interrupt context. Hold it for the shortest time possible — spinning wastes CPU.

spinlock_t lock;
spin_lock(&lock);
// critical section
spin_unlock(&lock);

Spinlocks and Interrupts

If an interrupt handler tries to take a spinlock already held on the same CPU, you deadlock. Use spin_lock_irqsave to disable local interrupts while holding the lock.

unsigned long flags;
spin_lock_irqsave(&lock, flags);
// safe even against IRQs
spin_unlock_irqrestore(&lock, flags);

Mutexes and Semaphores

A mutex puts the waiting thread to sleep instead of spinning. It is efficient for longer critical sections but is only usable in process context, never in an interrupt handler.

struct mutex m;
mutex_init(&m);
mutex_lock(&m);
// may sleep here
mutex_unlock(&m);

Choosing the Right Primitive

Quick decision guide:

  • Short, may run in IRQ context -> spinlock
  • Long, process context, can sleep -> mutex
  • Single counter or flag -> atomic

Read-Copy-Update (RCU)

RCU allows lock-free reads of shared data while writers create a new copy and swap a pointer. Readers see either the old or new version, never a torn one. It scales superbly for read-mostly structures.

Memory Barriers

Compilers and CPUs reorder memory accesses. A memory barrier (smp_mb(), smp_wmb()) forces ordering so other cores observe writes in the intended sequence — vital for lock-free code.

Deadlock Avoidance

To prevent deadlock: always acquire multiple locks in a fixed global order, keep critical sections tiny, and never call a sleeping function while holding a spinlock or interrupts are disabled.

Quick Check

Test your kernel concurrency knowledge.

Recap

You learned kernel synchronization:

  • Atomics protect single values via lock-prefixed instructions
  • Spinlocks busy-wait and work in IRQ context; use irqsave variants
  • Mutexes sleep and are process-context only
  • RCU and memory barriers enable scalable lock-free reads
무료로 시작

AI 튜터와 함께 Assembly을(를) 배우세요 — 무료

브라우저에서 실제 코드를 작성하고 실행하며, 24/7 AI 튜터로부터 즉각적인 도움을 받고, 웹이나 앱에서 중단한 부분부터 계속 학습하세요.

코스
12
레슨
48

자주 묻는 질문

“커널 공간의 동기화와 동시성” 강의는 무료인가요?

네 — “커널 공간의 동기화와 동시성” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Assembly Language & x86 Low-Level Systems Programming 강의 전체를 잠금 해제할 수 있습니다. Assembly Language & x86 Low-Level Systems Programming 강의에는 총 4개의 강의가 포함되어 있습니다.

“커널 공간의 동기화와 동시성”에서 뭘 배우나요?

스핀락, 뮤텍스, 원자적 연산을 사용하고 인터럽트 컨텍스트와 프로세스 컨텍스트의 차이를 이해하며 커널의 공유 데이터를 안전하게 관리합니다. 브라우저에서 직접 실행하는 실습 코드로 Assembly Language & x86 Low-Level Systems Programming을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Assembly Language & x86 Low-Level Systems Programming을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Assembly Language & x86 Low-Level Systems Programming은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.

“커널 공간의 동기화와 동시성” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Assembly Language & x86 Low-Level Systems Programming 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Assembly Language & x86 Low-Level Systems Programming 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 커널 공간 소개
  2. 간단한 장치 드라이버 작성
  3. 하드웨어와 직접 상호 작용
  4. 커널 공간의 동기화와 동시성
← Assembly Language & x86 Low-Level Systems Programming(으)로 돌아가기