Lecture3 - CSCE 313: Introduction to Computer Systems...

Info iconThis preview shows pages 1–12. 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

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: CSCE 313: Introduction to Computer Systems Spring 2011 Dr. Ronnie Ward Pthreads - POSIX Threads Chapter 12 in textbook Some slides adopted and modified from Dr. Bettati. POSIX Threads • Why Threads? – Latency Hiding / Multiprogramming (covered earlier) – Ease of Programming (covered now) • POSIX Threads (R&R, Chapter 12) – Thread Management – Thread Safety – Thread Attributes 2/14/12 3 Threads • Thread – A sequential execution stream within a process (also called lightweight process) – Threads in a process share the same address space • Thread concurrency – Easier to program overlapping I/O with threads than signals – Users like to do several things at a time: Web browser – A server (e.g. file server) serves multiple requests 4 2/14/12 Why Threads ? • Many interactive applications run in loops. • For example, an interactive game. • Reference [B.O. Gallmeister, “POSIX.4, 5 2/14/12 while (1) { /* Read Keyboard */ /* Update Display */ /* AND emit sounds */ } Why Threads ? • Many interactive applications run in loops. • For example, an interactive game. • Reference [B.O. Gallmeister, “POSIX.4, 6 2/14/12 while (1) { /* Synchronize to Highest Frequency */ /* Read Keyboard */ /* AND Read Mouse */ /* Recompute Player Position */ /* Update Display */ /* AND all other lights */ /* AND emit sounds */ /* AND more sounds */ } Why Threads ? • Many interactive applications run in loops. • For example, an interactive game. • Reference [B.O. Gallmeister, “POSIX.4, 7 2/14/12 while (1) { /* Synchronize to Highest Frequency */ /* Read Keyboard */ /* AND Read Mouse */ /* Recompute Player Position */ /* Update Display */ /* AND all other lights */ /* AND emit sounds */ /* AND more sounds */ /* AND move game physically */ } Suddenly, application is getting complex! • It ain’t over yet! • What about compute-intensive operations, like AI, video compression? • How about Signal Handlers? Reading the Mouse 8 2/14/12 while (1) { /* Synchronize to Highest Frequency */ /* Read Keyboard */ /* AND Read Mouse */ /* Recompute Player Position */ /* Update Display */ /* AND all other lights */ /* AND emit sounds */ /* AND more sounds */ /* AND move game physically */ } read_mouse() { } Reading the Mouse (II) 9 2/14/12 while (1) { /* Synchronize to Highest Frequency */ /* Read Keyboard */ /* AND Read Mouse */ /* Recompute Player Position */ /* Update Display */ /* AND all other lights */ /* AND emit sounds */ /* AND more sounds */ /* AND move game physically */ } int main() { read_mouse() { } } fork() S e pa ra te Pro c e s s Function Call vs. Thread 10 2/14/12 Reading the Mouse (III) 11 2/14/12 while (1) { /* Synchronize to Highest Frequency */ /* Read Keyboard */...
View Full Document

This note was uploaded on 02/14/2012 for the course CSCE 313 taught by Professor Gu during the Spring '11 term at Texas A&M.

Page1 / 33

Lecture3 - CSCE 313: Introduction to Computer Systems...

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

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