threads - Threads (CSE 422S) Dante Cannarozzi Washington...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Threads (CSE 422S) Dante Cannarozzi Washington University djc2@cse.wustl.edu www.cse.wustl.edu/~djc2 2-Ken Wong, Oct 2008 A Modern Process (1) Separate idea of execution from resource grouping Thread A unit of local dispatching (scheduling) and has priority Has an execution path (is a thread of control) Has a computation state (stack, set of CPU registers) Global variables are shared by all threads System state shared by threads File descriptors, working directory, etc. 3-Ken Wong, Oct 2008 A Modern Process (2) Single-Threaded Process Model Multithreaded Process Model User Stack Kernel Stack User Address Space Process Control Block UID, GID Thread Control Block User Stack Kernel Stack User Address Space Process Control Block Thread Thread Control Block User Stack Kernel Stack Thread Thread Control Block User Stack Kernel Stack Thread UID, GID 4-Ken Wong, Oct 2008 A Modern Process (3) Stack Global Vars. Instructions PC1 SP1 Kernel Stack, Memory Map, File Descriptors, etc. User Space Kernel Space SP2 SP3 PC2 PC3 Thread Library Kernel Threads Lightweight Processes 5-Ken Wong, Oct 2008 Database Server Example Benefits Simplifies sharing of memory and file descriptors Concurrent execution of relatively independent tasks Increase overall throughput for some problems Worker Threads Database Cache User Space Kernel Space Request Disk I/O Dispatcher Thread Wait to read task list Read disk into DB cache if necessary Send reply 6-Ken Wong, Oct 2008 Thread Execution (1 Processor) Process A Thread 0 Thread 1 Process B Thread 0 Unix Kernel I/O Time Process A Process B Unix Kernel I/O Time Single-Threaded Processes Multithreaded Processes Can overlap own I/O with own CPU usage 7-Ken Wong, Oct 2008 Thread Library Implementations User-Space Self-contained user-level library All code and structures are in user-space Depends on a small number of OS system calls N:1 model N user threads mapped to 1 kernel thread or process Kernel-Space Thin user-space layer Substantial amount of kernel code and structures 1:1 model and N:M model 1 user thread mapped to 1 kernel thread or N user threads mapped to M kernel threads 8-Ken Wong, Oct 2008 N:1 and 1:1 Model of Multithreading User Space Kernel Space CPU 1:1 Model CPU Thread Library User Space Kernel Space N:1 Model Process Scheduler Process Scheduler Thread Scheduler 9-Ken Wong, Oct 2008 N:1 Model of Multithreading (1) Many threads mapped onto ONE process Implementation Put thread package entirely in user space Thread creation-scheduling-synchronization done in user space Allocate stack for each thread Kernel has no knowledge of threads Thread Table Analogous to process table, but contains only thread state Dispatcher An ordinary function called during startup; calls main() Use setjmp(3)/longjmp(3) in place of function call/return Choose thread to run; if (context switch) Load new hardware state; Resume selected thread execution (load PC); 10...
View Full Document

Page1 / 47

threads - Threads (CSE 422S) Dante Cannarozzi Washington...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online