Presentation is loading. Please wait.

Presentation is loading. Please wait.

Operating Systems Parallel Systems and Threads (Soon to be basic OS knowledge)

Similar presentations


Presentation on theme: "Operating Systems Parallel Systems and Threads (Soon to be basic OS knowledge)"— Presentation transcript:

1 Operating Systems Parallel Systems and Threads (Soon to be basic OS knowledge)

2 Parallelism F Multiple processes concurrently Process 1 Process 2 CPU1 Process 1 Process 2 CPU1 CPU2 Pseudo- Parallelism True Parallelism

3 Parallel Hardware CPU1 Registers CPU2 Memory Disk Controller Disk Symmetric Multi-Processors Increasingly common. How to modify OS to handle new hardware?

4 Two Operating Systems F Divide memory in two F Run an independent OS in each F Each has it’s own processes F Drawbacks –Twice as much memory used for OS –IPC tough –Who controls memory and disk? (convenient) –Inefficient scheduling (efficient)

5 Sharing the Operating System Processor 1 Program Counter Stack Pointer Processor 2 Program Counter Stack Pointer Main Memory OS Code OS Common Data P1’s OS Data P2’s OS Data P1’s OS Stack P2’s OS Stack Shared? (see sample code) stackprocess table current processdevice queues Race Conditions!

6 Example Multiprocessor OSes F Almost all new OSes! F Designed from start –Windows NT –Mach F Unix –AT&T System V –Sun Solaris –HP Unix –Digital Unix –IBM AIX –SGI Irix

7 Threads Software Multi-Processors

8 Threads (Lightweight Processes) F Basic unit of CPU utilization –(“What?!” you say) F Own –program counter –register set –stack space F Shares –code section –data section –OS resources text segment data segment Program Counter (Threads) C stack B stackA stack ABC ABC “Multithreaded Program” Process

9 Stack A(int tmp) { B(); printf(tmp) ; } B() { C(); } C() { A(2); } A: tmp = 2 C B A: tmp = 1

10 Example: A Threaded Spreadsheet Command Thread Spreadsheet Data Other Data Display Thread Recalculate Thread

11 What Kinds of Programs to Thread? F Independent tasks –ex: debugger needs gui, program, perf monitor… –especially when blocking for I/O! F Single program, concurrent operation –Servers u ex: file server, web server –OS kernels u concurrent requests by multiple users -- no protection needed in kernel

12 Thread Benefits F “What about just using processes with shared memory?” –fine –debugging tougher (more thread tools) –processes slower u 30 times slower to create on Solaris u slower to destroy u slower to context switch among –processes eat up memory u few thousand processes not ok u few thousand threads ok

13 Threads Standards F POSIX (Pthreads) –Common API –Almost all Unix’s have thread library F Win32 and OS/2 –very different from POSIX, tough to port –commercial POSIX libraries for Win32 –OS/2 has POSIX option F Solaris –started before POSIX standard –likely to be like POSIX

14 Do they Work? F Operating systems –Mach, Windows NT, Windows 95, Solaris, IRIX, AIX, OS/2, OSF/1 –Millions of (unforgiving) users F NFS, SPECfp, SPECint 14812162024CPUs

15 Levels of Threads User Level Thread Thread Kernel Thread Process A Process B


Download ppt "Operating Systems Parallel Systems and Threads (Soon to be basic OS knowledge)"

Similar presentations


Ads by Google