Problem 1: Concepts (Please be concise)

Similar documents
Linux Programming

CLIENT-SIDE PROGRAMMING

CSci 4061 Introduction to Operating Systems. Synchronization Basics: Locks

CS 25200: Systems Programming. Lecture 26: Classic Synchronization Problems

Socket Programming for TCP and UDP

CS 345 Operating Systems. Tutorial 2: Treasure Room Simulation Threads, Shared Memory, Synchronization

15-213/ Final Exam Notes Sheet Spring 2013!

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

CMPSC 311- Introduction to Systems Programming Module: Network Programming

Programming Ethernet with Socket API. Hui Chen, Ph.D. Dept. of Engineering & Computer Science Virginia State University Petersburg, VA 23806

CMPSC 311- Introduction to Systems Programming Module: Network Programming

Programming Ethernet with Socket API. Hui Chen, Ph.D. Dept. of Engineering & Computer Science Virginia State University Petersburg, VA 23806

Synchronization. Dr. Yingwu Zhu

CSC209H Lecture 9. Dan Zingaro. March 11, 2015

CS 43: Computer Networks. 05: Socket Programming September 12-14, 2018

Oral. Total. Dated Sign (2) (5) (3) (2)

Concurrent Server Design Multiple- vs. Single-Thread

CSE 333 Section 8 - Client-Side Networking

Pre-lab #2 tutorial. ECE 254 Operating Systems and Systems Programming. May 24, 2012

ECE 435 Network Engineering Lecture 2

Socket Programming TCP UDP

Socket Programming. CSIS0234A Computer and Communication Networks. Socket Programming in C

Network programming(i) Lenuta Alboaie

Semaphores. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Overview. Administrative. * HW# 5 Due next week. * HW# 5 : Any Questions. Topics. * Client Server Communication. * 12.

Interprocess Communication. Originally multiple approaches Today more standard some differences between distributions still exist

Tutorial on Socket Programming

Lecture 7. Followup. Review. Communication Interface. Socket Communication. Client-Server Model. Socket Programming January 28, 2005

sottotitolo Socket Programming Milano, XX mese 20XX A.A. 2016/17 Federico Reghenzani

A Socket Example. Haris Andrianakis & Angelos Stavrou George Mason University

Synchroniza+on II COMS W4118

High Performance Computing Lecture 21. Matthew Jacob Indian Institute of Science

Synchronization and Semaphores. Copyright : University of Illinois CS 241 Staff 1

NETWORK AND SYSTEM PROGRAMMING

Hybrid of client-server and P2P. Pure P2P Architecture. App-layer Protocols. Communicating Processes. Transport Service Requirements

TCP: Three-way handshake

CSE 333 SECTION 6. Networking and sockets

W4118 Operating Systems. Instructor: Junfeng Yang

CS 470 Spring Mike Lam, Professor. Semaphores and Conditions

Synchronization. Semaphores implementation

CSE 124 Discussion Section Sockets Programming 10/10/17

CS307 Operating Systems Processes

Processes. Process Concept. The Process. The Process (Cont.) Process Control Block (PCB) Process State

Synchronization Primitives

POSIX / System Programming

Data Races and Deadlocks! (or The Dangers of Threading) CS449 Fall 2017

CS-345 Operating Systems. Tutorial 2: Grocer-Client Threads, Shared Memory, Synchronization

Embedded System Design

Plan. Demos. Next Project. CSCI [4 6]730 Operating Systems. Hardware Primitives. Process Synchronization Part II. Synchronization Part 2

Synchronization II. Today. ! Condition Variables! Semaphores! Monitors! and some classical problems Next time. ! Deadlocks

LSN 13 Linux Concurrency Mechanisms

CS 153 Lab6. Kishore Kumar Pusukuri

Warm-up question (CS 261 review) What is the primary difference between processes and threads from a developer s perspective?

CSE 333 Lecture 16 - network programming intro

Processes often need to communicate. CSCB09: Software Tools and Systems Programming. Solution: Pipes. Recall: I/O mechanisms in C

System Programming. Sockets

CS321: Computer Networks Socket Programming

This exam paper contains 8 questions (12 pages) Total 100 points. Please put your official name and NOT your assumed name. First Name: Last Name:

Condition Variables. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

WinSock. What Is Sockets What Is Windows Sockets What Are Its Benefits Architecture of Windows Sockets Network Application Mechanics

CSE 421/521 - Operating Systems Fall 2011 Recitations. Recitation - III Networking & Concurrent Programming Prof. Tevfik Kosar. Presented by...

ICT 6544 Distributed Systems Lecture 5

Process Synchronization(2)

IP Addresses, DNS. CSE 333 Summer Teaching Assistants: Renshu Gu William Kim Soumya Vasisht

A Quick Guide to Networking Software by J. Sanguino 2 nd Edition: February 2010

Synchronization and Semaphores. Copyright : University of Illinois CS 241 Staff 1

The Berkeley Sockets API. Networked Systems Architecture 3 Lecture 4

Multithreading Programming II

// socket for establishing connections

MSc Integrated Electronics Networks Assignment. Investigation of TCP/IP Sockets and Ports. Gavin Cameron

Networked Applications: Sockets. End System: Computer on the Net

IP Addresses, DNS. CSE 333 Spring Instructor: Justin Hsia

Introduction to Network Programming in C/C++

Introduction to Socket Programming

Network Programming in C. Networked Systems 3 Laboratory Sessions and Problem Sets

The User Datagram Protocol

Process Synchronization. studykorner.org

Network Programming in C: The Berkeley Sockets API. Networked Systems 3 Laboratory Sessions

Announcements. Class feedback for mid-course evaluations Receive about survey to fill out until this Friday

External data representation

Carnegie Mellon. Synchroniza+on : Introduc+on to Computer Systems Recita+on 14: November 25, Pra+k Shah (pcshah) Sec+on C

THREADS. Jo, Heeseung

[537] Semaphores. Tyler Harter

Condition Variables. Dongkun Shin, SKKU

THREADS VS. PROCESSES

CS345 Opera,ng Systems. Φροντιστήριο Άσκησης 2

ECE 435 Network Engineering Lecture 2

CS F-MID Midterm October 25, 2001

In class we examined the need for concurrent execution paths like a consumer and a producer to synchronize their access to a shared ring buffer.

Concurrency. Chapter 5

Synchronization. CSE 2431: Introduction to Operating Systems Reading: Chapter 5, [OSC] (except Section 5.10)

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

Concurrent Programming Lecture 10

Introduction to PThreads and Basic Synchronization

CSMC 412. Computer Networks Prof. Ashok K Agrawala Ashok Agrawala Set 2. September 15 CMSC417 Set 2 1

Process Synchronization

Operating systems. Lecture 3 Interprocess communication. Narcis ILISEI, 2018

COP 4225 Advanced Unix Programming. Synchronization. Chi Zhang

Synchronization II. q Condition Variables q Semaphores and monitors q Some classical problems q Next time: Deadlocks

Communication. Sockets (Haviland Ch. 10)

Transcription:

Problem 1: Concepts (Please be concise) 1) Consider the use of threads vs. the select() system call for asynchronous I/O. Name one advantage of each approach. 2) Consider a dynamically allocated linked-list where items are added and deleted over time and the list is unordered. Each node of the list has a unique virtual address and the process is allocated a fixed number of memory pages. By far, the most common operation is a linear scan through all elements of the list. If you were concerned about virtual memory performance for this operation, how would you organize this list? 3) In socket programming, it is good practice to put hton* calls around port numbers and IP addresses. Why? 4) Suppose the system offers two types of locks, a spinlock (which blocks a thread by spinning in a while-loop) and a mutexlock (which blocks a thread by putting it to sleep). When might you prefer to use a spinlock? 5) Some compilers do in-lining of functions before generating the assembly code. In-lining replaces a function call with the body of the function. In the example below, foo is inlined within bar. void foo (int a, int b) { return (a+b); } void bar () {int a,b,c; c = foo (a,b); } becomes void bar () { int a,b,c; c=a+b; } In-lining may be helpful with virtual memory. Why? 6) Sketch a solution to this problem using semaphores. Synchronize a group of threads that each wish to connect to a DB server by completing DB_thread below and giving the semaphore an initial value. At most K connections to a DB server are allowed at any one time. You should use the semaphore functions down (sem_t *) and up (sem_t *). These functions are also sometimes called P/V or wait/post respectively. sem_t s = ; void DB_thread ( ) { // this is the function all threads call DB.connect ( ); 7) Suppose that when threads finish an activity they execute a simple counter increment statement Counter++;(where Counter is a global with an initial value of 0). Suppose this statement is executed concurrently by 1000 threads. What are the possible values of Counter at the end? Why 1

Problem 2: Virtual Memory Consider the code fragment below. Suppose the resulting process is allocated K memory frames, the page size/frame size is 2K, and arrays are stored by row in the virtual address space. Only consider the memory needed for the array. int A[2048][2048]; for (i=0; i<2048; i++) for (j=0; j<2048; j++) A[i][j] = 0; // Line #1 a) How many page faults will this process suffer at Line #1? Why? b) Replace A[i][j] = 0 with A[j][i] = 0. How many page faults will this process suffer at Line #1? Why? 2

Problem 3: Synchronization Note: this is for practice and is likely harder than I would put on exam. Threaded-merger. Write a program that merges data from multiple input streams into a single output stream. The main program takes a set of filenames and starts a reader thread for each one The yellow buffer is like a ring buffer Readers exit when they see EOF on their input files Writer must distinguish between buffer empty and input done 3

Problem 4: Network Programming One problem with Internet servers is that the client must know the machine or address name of the server. Suppose instead that a client wishes to discover a server based on what service it provides, e.g. news, weather, and so on. We call this this the service_name. Suppose a discovery service maintains <service_name, struct sockaddr> pairs (the latter is the socket address of service_name); and the discovery service is running on a server in the Internet. The discovery service has several operations that a client may use but we will focus on LOOKUP <service_name> which returns the associated address if the service exists. Request message (string format): LOOKUP news <blank_line> Assume the reply to LOOKUP is formatted not as a string but as an encoded data type (reply_t): typedef struct { int exists; // does service exists: 1 yes, 0 no struct sockaddr the_addr; // the addr of the service } reply_t; You write a simple client that uses the discovery service to lookup and connect to a service named news. 1) What crucial piece of information did I omit that you need in order to write this simple client? 2) Assuming the presence of the information from (1) above, write this client (using socket code). No error checking code is needed. 4

System call signatures (not all may be needed): Sockets: int socket(pf_inet, SOCK_STREAM, 0); int bind (int s, struct sockaddr *addr, int len); int accept (int s, struct sockaddr *addr, int *len ); int connect (int s, struct sockaddr *name, int len); int listen (int s, int backlog); struct sockaddr { sa_family_t sin_famly; // AF_INET u_intl6_t sin_port; // port: network byte order struct in_addr sin_addr; // IP_addr: network byte order } uint32_t htonl(uint32_t hostlong); uint16_t htons(uint16_t hostshort); uint32_t ntohl(uint32_t netlong); uint16_t ntohs(uint16_t netshort); Synchronization: int sem_init (sem_t *S, 0, int init_val); int sem_wait (sem_t *S); // like P int sem_post (sem_t *S); // like V (or signal) pthread_t thread = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_lock (pthread_mutex_t *mutex); pthread_mutex_unlock (pthread_mutex_t *mutex); pthread_cond_t cond = PTHREAD_COND_INITIALIZER; int pthread_cond_signal(pthread_cond_t*cond); int pthread_broadcast(pthread_cond_t*cond); int pthread_cond_wait(pthread_cond_t*cond, pthread_mutex_t*mutex); Misc: void fork(); pid_t wait (int *status); int pipe (ends[2]); size_t sizeof (<type> or <var>); ssize_t read(int fd, void *buf, size_t count); ssize_t write(int fd, const void *buf, size_t count); 5