shahriar pirnia operating system سيستم عامل

18
Shahriar Pirnia http:// www.pirnia.net Operating system Operating system ل ما ع م ت س ي سل ما ع م ت س ي س

Upload: clementine-lee

Post on 18-Jan-2018

230 views

Category:

Documents


0 download

DESCRIPTION

The Thread Model (2) Items shared by all threads in a process Items private to each thread

TRANSCRIPT

Page 1: Shahriar Pirnia  Operating system سيستم عامل

Shahriar Pirnia http://www.pirnia.net

Operating systemOperating systemسيستم عاملسيستم عامل

Page 2: Shahriar Pirnia  Operating system سيستم عامل

ThreadsThe Thread Model (1)

(a) Three processes each with one thread(b) One process with three threads

Page 3: Shahriar Pirnia  Operating system سيستم عامل

The Thread Model (2)

• Items shared by all threads in a process• Items private to each thread

Page 4: Shahriar Pirnia  Operating system سيستم عامل

The Thread Model (3)

Each thread has its own stack

Page 5: Shahriar Pirnia  Operating system سيستم عامل

Thread Usage (1)

A word processor with three threads

Page 6: Shahriar Pirnia  Operating system سيستم عامل

Thread Usage (2)

A multithreaded Web server

Page 7: Shahriar Pirnia  Operating system سيستم عامل

Thread Usage (3)

• Rough outline of code for previous slide(a) Dispatcher thread(b) Worker thread

Page 8: Shahriar Pirnia  Operating system سيستم عامل

Thread Usage (4)

Three ways to construct a server

Page 9: Shahriar Pirnia  Operating system سيستم عامل

Implementing Threads in User Space

A user-level threads package

Page 10: Shahriar Pirnia  Operating system سيستم عامل

Implementing Threads in the Kernel

A threads package managed by the kernel

Page 11: Shahriar Pirnia  Operating system سيستم عامل

Hybrid Implementations

Multiplexing user-level threads onto kernel- level threads

Page 12: Shahriar Pirnia  Operating system سيستم عامل

Scheduler Activations• Goal – mimic functionality of kernel threads

– gain performance of user space threads• Avoids unnecessary user/kernel transitions• Kernel assigns virtual processors to each process

– lets runtime system allocate threads to processors• Problem:

Fundamental reliance on kernel (lower layer) calling procedures in user space (higher layer)

Page 13: Shahriar Pirnia  Operating system سيستم عامل

Pop-Up Threads

• Creation of a new thread when message arrives(a) before message arrives(b) after message arrives

Page 14: Shahriar Pirnia  Operating system سيستم عامل

Making Single-Threaded Code Multithreaded (1)

Conflicts between threads over the use of a global variable

Page 15: Shahriar Pirnia  Operating system سيستم عامل

Making Single-Threaded Code Multithreaded (2)

Threads can have private global variables

Page 16: Shahriar Pirnia  Operating system سيستم عامل

Threads in POSIX

The principal POSIX thread calls.

Page 17: Shahriar Pirnia  Operating system سيستم عامل

The ls Command

Steps in executing the command ls type to the shell

Page 18: Shahriar Pirnia  Operating system سيستم عامل

Flags for Linux clone

Bits in the sharing_flags bitmap