Download
concurrency introduction n.
Skip this Video
Loading SlideShow in 5 Seconds..
Concurrency: Introduction PowerPoint Presentation
Download Presentation
Concurrency: Introduction

Concurrency: Introduction

1 Views Download Presentation
Download Presentation

Concurrency: Introduction

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Concurrency: Introduction Ilsoo Byun(isbyun@dcslab.snu.ac.kr) School of Computer Science and Engineering Seoul National University

  2. Contents • Introduction to Thread • Linux Implementation • Concurrency Problem • Necessity of Atomicity • Summary

  3. Process vs Thread • Similarities • Unit of a context switch • PC • Registers • Differences • Process Context Block/Thread Context Block • Process can not access the address space of other processes but threads of a process can access every addressin the process. • After context switching between threads, the address space remains the same. • With threads, there can be multiple stacks in the address space.

  4. A Single- and Multi-Threaded Address space Code Code Data Data BSS BSS Heap Heap Free Stack(2) Stack Stack(1) (a) Sigle-threaded (b) Multi-threaded

  5. Linux Implementation (1) TCB Thread ID 4 State: Ready PID 111222 PCB Thread ID 5 State: Ready User ID PC SP Group ID Registers Registers Address space Open files PC SP Sockets etc Separate the concept of a process from a thread of control Process is just a container for threads Each thread has its own CPU execution state

  6. Linux Implementation (2) Thread ID 4 State: Ready Thread ID 5 State: Ready Ready Queue PC SP PC SP Registers Registers • TCB is the unit of a context switch • Ready queue, wait queues, etc. now contain pointers to TCB • Context switch cause CPU state to be copied to /from the TCB • TCB's are smaller and cheaper than PCB • Linux TCB(thread_struct) has 24 fields • Linux PCB(task_struct) has 106 fields

  7. Thread Creation

  8. Thread Trace (1)

  9. Thread Trace (2)

  10. Thread Trace (3)

  11. Why it is a problem? counter = 20000000 or counter = 19345221 or counter = 18221041 • Shared Data • Running order depends on the scheduler decision

  12. Uncontrolled Scheduling Simply adding 1 to counter requires three instructions

  13. Uncontrolled Scheduling

  14. Necessity of Atomicity • Add more powerful instructions? • Cannot support all cases that require atomic operations. • Provide synchronization primitives for the general purpose • Access critical section in a synchronized and controlled manner • Reliably produce result despite the nature of concurrent execution

  15. Summary • Threads • Multiple points of execution in a process • Accessing shared data, non-deterministic behavior can occur. • To support atomic operation, synchronization primitives are required.