Carnegie Mellon Recitation 11: ProxyLab 15-213 Fall 2009 November 16, 2009 Including Material from Previous Semesters' Recitations.

Slides:



Advertisements
Similar presentations
Carnegie Mellon 1 Concurrent Programming / : Introduction to Computer Systems 23 rd Lecture, Nov. 15, 2012 Instructors: Dave O’Hallaron, Greg.
Advertisements

1 Carnegie Mellon Proxylab and stuff : Introduction to Computer Systems Recitation 13: November 19, 2012 Donald Huang (donaldh) Section M.
1 Carnegie Mellon Networking Basics and Concurrent Programming Shiva (sshankar) Section M.
Lecture 4: Concurrency and Threads CS 170 T Yang, 2015 Chapter 4 of AD textbook.
Threads By Dr. Yingwu Zhu. Review Multithreading Models Many-to-one One-to-one Many-to-many.
– 1 – , F’02 Traditional View of a Process Process = process context + code, data, and stack shared libraries run-time heap 0 read/write data Program.
Fork Fork is used to create a child process. Most network servers under Unix are written this way Concurrent server: parent accepts the connection, forks.
Threads 1 CS502 Spring 2006 Threads CS-502 Spring 2006.
Pthreads Operating Systems Hebrew University of Jerusalem Spring 2004.
Threads© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer Science Department.
Concurrent HTTP Proxy with Caching Ashwin Bharambe Monday, Dec 4, 2006.
1 Concurrent Programming Andrew Case Slides adapted from Mohamed Zahran, Jinyang Li, Clark Barrett, Randy Bryant and Dave O’Hallaron.
PRINCIPLES OF OPERATING SYSTEMS Lecture 6: Processes CPSC 457, Spring 2015 May 21, 2015 M. Reza Zakerinasab Department of Computer Science, University.
10/16/ Realizing Concurrency using the thread model B. Ramamurthy.
Programming with TCP – III 1. Zombie Processes 2. Cleaning Zombie Processes 3. Concurrent Servers Using Threads  pthread Library Functions 4. TCP Socket.
B. RAMAMURTHY 10/24/ Realizing Concurrency using the thread model.
1 Concurrent Programming. 2 Outline Concurrent programming –Processes –Threads Suggested reading: –12.1, 12.3.
Carnegie Mellon 1 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Concurrent Programming : Introduction to Computer.
CS333 Intro to Operating Systems Jonathan Walpole.
Week 16 (April 25 th ) Outline Thread Synchronization Lab 7: part 2 & 3 TA evaluation form Reminders Lab 7: due this Thursday Final review session Final.
Threads Chapter 26. Threads Light-weight processes Each process can have multiple threads of concurrent control. What’s wrong with processes? fork() is.
12/22/ Thread Model for Realizing Concurrency B. Ramamurthy.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
CSC 360, Instructor: Kui Wu Thread & PThread. CSC 360, Instructor: Kui Wu Agenda 1.What is thread? 2.User vs kernel threads 3.Thread models 4.Thread issues.
Thread S04, Recitation, Section A Thread Memory Model Thread Interfaces (System Calls) Thread Safety (Pitfalls of Using Thread) Racing Semaphore.
Carnegie Mellon 1 Concurrent Programming / : Introduction to Computer Systems 22 nd Lecture, Nov. 11, 2014 Instructors: Greg Ganger, Greg.
Concurrency I: Threads Nov 9, 2000 Topics Thread concept Posix threads (Pthreads) interface Linux Pthreads implementation Concurrent execution Sharing.
Concurrency Threads Synchronization Thread-safety of Library Functions Anubhav Gupta Dec. 2, 2002 Outline.
2.2 Threads  Process: address space + code execution  There is no law that states that a process cannot have more than one “line” of execution.  Threads:
1 Introduction to Threads Race Conditions. 2 Process Address Space Revisited Code Data OS Stack (a)Process with Single Thread (b) Process with Two Threads.
B. RAMAMURTHY 5/10/2013 Amrita-UB-MSES Realizing Concurrency using the thread model.
7/9/ Realizing Concurrency using Posix Threads (pthreads) B. Ramamurthy.
CMSC 421 Spring 2004 Section 0202 Part II: Process Management Chapter 5 Threads.
A thread is a basic unit of CPU utilization within a process Each thread has its own – thread ID – program counter – register set – stack It shares the.
CS703 – Advanced Operating Systems By Mr. Farhan Zaidi.
Realizing Concurrency using the thread model
Instructor: Haryadi Gunawi
Threads Synchronization Thread-safety of Library Functions
Realizing Concurrency using the thread model
Threads in C Caryl Rahn.
Threads Threads.
Boost String API & Threads
Copyright ©: Nahrstedt, Angrave, Abdelzaher
CS399 New Beginnings Jonathan Walpole.
Thread Programming.
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Chapter 4: Threads.
Concurrent Programming November 13, 2008
Concurrency I: Threads April 10, 2001
Threads and Cooperation
Concurrent Servers Topics Limitations of iterative servers
Realizing Concurrency using Posix Threads (pthreads)
Operating Systems Lecture 13.
Recitation 14: Proxy Lab Part 2
Realizing Concurrency using the thread model
Realizing Concurrency using the thread model
CS510 Operating System Foundations
Pthread Prof. Ikjun Yeom TA – Mugyo
Jonathan Walpole Computer Science Portland State University
Realizing Concurrency using the thread model
Realizing Concurrency using Posix Threads (pthreads)
Concurrent Programming : Introduction to Computer Systems 23rd Lecture, Nov. 13, 2018
Realizing Concurrency using the thread model
Concurrent Programming CSCI 380: Operating Systems
Realizing Concurrency using Posix Threads (pthreads)
Concurrent Programming November 13, 2008
Lecture 19: Threads CS April 3, 2019.
Instructor: Brian Railing
Threads CSE 2431: Introduction to Operating Systems
Concurrent Programming
Presentation transcript:

Carnegie Mellon Recitation 11: ProxyLab Fall 2009 November 16, 2009 Including Material from Previous Semesters' Recitations.

Carnegie Mellon Overview Lecture Review  Unix Socket Interface  Echo Server ProxyLab  Pair Programming  Introduction to the Lab Threading

Carnegie Mellon Lecture Review

Carnegie Mellon Unix Socket Interface socket() bind() listen() accept() connect() send() recv() Read the man pages to get a better understanding of how they're used and the errors that may occur.

Carnegie Mellon Example Echo Server

Carnegie Mellon ProxyLab

Carnegie Mellon Pair Programming ProxyLab is the first lab on which you can work in pairs, but you can do it alone if you want. Finding a programming partner can be harder than finding a date, but here are two ways to start:  Ask someone before, during, or after a recitation or lecture.  Post a personal ad on the message board. Use common etiquette:  If someone thinks you'll be working with them, but you change your mind, let them know.  When working with someone, do your fair share of the work and be available to meet with your partner. Document your code so that your partner can understand it. Understand the whole program, even the parts your partner worked on.

Carnegie Mellon Pair Programming Methods You have two basic options:  Work together programming on the same computer.  This makes your program better the first time through and helps you catch bugs, but may not be the most efficient method.  Code separately, especially by taking advantage of the modularity of your program. Ways to share code:  code back and forth.  Giving each other access to a part of your AFS space.  Use revision control software. –We recommend git ( –See for more info on revision control.

Carnegie Mellon ProxyLab Introduction Proxies are used for various reasons:  Firewalls  Filters  Removing identifying information from requests  Caching You will write a simple proxy that processes requests concurrently and caches web objects.  Requires knowledge of network programming, concurrency, and synchronization.

Carnegie Mellon Proxy Example Yes! Here it is I can has ? I can has ? Yes! Here it is

Carnegie Mellon Caching Proxy A proxy that remembers web objects it fetches for a user. So if a web object is requested again, the proxy server can immediately serve the web object, instead of fetching it again. I can has ? Yes! Here it is Hey! I remember that site! 2

Carnegie Mellon ProxyLab Appropriate and graceful error handling. Document design decisions Code organization  Break proxy into multiple functions Complete lab in three stages  Basic sequential proxy  Handling concurrent requests  Caching Understand what is robust about the rio package  Behavior of network sockets Each member of a group must understand everything in the group's program.

Carnegie Mellon Testing and Grading your Proxy No autograder, but everyone in a pair must submit his or her lab to Autolab! When done, each group will meet with a TA and demo its lab. The TAs will grade labs by hand. Test your proxy by setting up your browser to use your proxy.  For Firefox, use FoxyProxy:

Carnegie Mellon Running and Testing your Proxy hostname cobia.ics.cs.cmu.edu hpitelka hpitelka:

Carnegie Mellon Threading

Carnegie Mellon Multi-Threaded process shared libraries run-time heap 0 read-only data code Thread 1 context: Data registers Condition codes SP-1 PC-1 stack 1 Thread 1 Kernel context: VM structures Descriptor table Thread 2 context: Data registers Condition codes SP-2 PC-2 stack 2 Thread 2 Shared resources: Thread N context: Data registers Condition codes SP-N PC-N stack N Thread N … writable data Private Address Space

Carnegie Mellon Posix Threads (Pthreads) Interface Standard interface for ~60 functions  Creating and reaping threads.  pthread_create  pthread_join  Determining your thread ID  pthread_self  Terminating threads  pthread_cancel  pthread_exit  Synchronizing access to shared variables  pthread_rwlock_init  pthread_mutex_[un]lock  pthread_cond_init  pthread_rwlock_[wr]rdlock

Carnegie Mellon Multi-threaded Hello World /* hello.c - Pthreads "hello, world" program */ #include "csapp.h" void *thread(void *vargp); int main() { pthread_t tid; int i; for(i = 0; i < 42; ++i) { pthread_create(&tid, NULL, thread, NULL); pthread_join(tid, NULL); } exit(0); } /* thread routine */ void *thread(void *vargp) { printf("Hello, world!\n"); return NULL; } Thread attributes (usually NULL) Start routine arguments return value Start routine

Carnegie Mellon Exiting a process and thread pthread_exit() only terminates the current thread, NOT the process exit() terminates ALL the threads in the process, i.e., the process itself

Carnegie Mellon Joinable & Detached Threads Joinable thread can be reaped and killed by other threads  must be reaped (with pthread_join) to free memory resources. Detached thread cannot be reaped or killed by other threads  resources are automatically reaped on termination. Default state is joinable  use pthread_detach(pthread_self()) to make detached.

Carnegie Mellon Review Lecture Review  Unix Socket Interface  Echo Server ProxyLab  Pair Programming  Introduction to the Lab Threading Next: Synchronization and Thread Safety

Carnegie Mellon Questions?