1 Advanced Operating Systems - Fall 2009 Lecture 5 – January 26, 2009 Dan C. Marinescu Office: HEC 439 B. Office hours:

Slides:



Advertisements
Similar presentations
OPERATING SYSTEMS Threads
Advertisements

Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 AE4B33OSS Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Multithreaded Programming.
Threads. Objectives To introduce the notion of a thread — a fundamental unit of CPU utilization that forms the basis of multithreaded computer systems.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
國立台灣大學 資訊工程學系 Chapter 4: Threads. 資工系網媒所 NEWS 實驗室 Objectives To introduce the notion of a thread — a fundamental unit of CPU utilization that forms the.
Threads.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 6: Threads Chapter 4.
Chapter 4: Multithreaded Programming
Modified from Silberschatz, Galvin and Gagne ©2009 Lecture 7 Chapter 4: Threads (cont)
Chapter 4: Multithreaded Programming
Course: Operating Systems Instructor: Umar Kalim NUST Institute of Information Technology, Pakistan Operating Systems.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 4: Threads CS 170 TY, Sept 2011.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
4.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 4 Multithreaded Programming Objectives Objectives To introduce a notion of.
Based on Silberschatz, Galvin and Gagne  2009 Threads Definition and motivation Multithreading Models Threading Issues Examples.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 4: Threads Dr. Mohamed Hefeeda.
Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Silberschatz, Galvin and Gagne ©2007 Chapter 4: Threads.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 4: Threads Dr. Mohamed Hefeeda.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Objectives To introduce a notion of a thread.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Objectives Thread definitions and relationship to process Multithreading.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Chapter 4: Threads READ 4.1 & 4.2 NOT RESPONSIBLE FOR 4.3 &
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Multithreaded Programming.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Threads Overview Multithreading Models Threading Issues.
Chapter 4: Threads Adapted to COP4610 by Robert van Engelen.
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
國立台灣大學 資訊工程學系 Chapter 4: Threads. 資工系網媒所 NEWS 實驗室 Objectives To introduce the notion of a thread — a fundamental unit of CPU utilization that forms the.
Chapter 4: Threads. 4.2CSCI 380 Operating Systems Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Multithreaded Programming Overview.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 4 Operating Systems.
Chapter 4: Threads. 4.2 Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads.
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2011Operating System Concepts Essentials – 8 th Edition Chapter 4: Threads.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Threads A thread (or lightweight process) is a basic unit of CPU.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11: :30 AM.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Shan Gao Fall 2007 Department of Computer Science Georgia State University.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 4: Threads Modified from the slides of the text book. TY, Sept 2010.
Chapter 4: Threads.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Lecture 3 Threads Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Saurav Karmakar. Chapter 4: Threads  Overview  Multithreading Models  Thread Libraries  Threading Issues  Operating System Examples  Windows XP.
Chapter 4: Threads 羅習五. Chapter 4: Threads Motivation and Overview Multithreading Models Threading Issues Examples – Pthreads – Windows XP Threads – Linux.
CISC2200 Threads Fall 09. Process  We learn the concept of process  A program in execution  A process owns some resources  A process executes a program.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads (7 th Edition)
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Client-Server Communication
OPERATING SYSTEM CONCEPT AND PRACTISE
Chapter 4: Threads.
Nadeem MajeedChoudhary.
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Modified by H. Schulzrinne 02/15/10 Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Presentation transcript:

1 Advanced Operating Systems - Fall 2009 Lecture 5 – January 26, 2009 Dan C. Marinescu Office: HEC 439 B. Office hours: M, Wd 3 – 4:30.

2 Last, Current, Next Lecture Last time: Butler Lampson’s hints for system design The complexity of computing and communication systems State Processes Today Process handling by the kernel Inter-process communication Threads Next time: Process synchronization

3 Process Control Block (PCB)

4 Process scheduling

5 Context Switch When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process Context-switch time is overhead; the system does no useful work while switching Context switch time dependent on hardware support

6 Inter-process communication The need to communicate: User process - kernel process  to invoke kernel functions Kernel process - kernel process  the kernel is not monolithic User process - user process  users have rights too!! Basic strategies Shared memory Message passing

7 Shared memory Producer – consumer (reader - writer) model. Shared buffer  buffer(BUFFER_SIZE) Unbounded: the produce could always write; the consumer may have to wait for new item Bounded: the produce may have to wait for buffer space the consumer may have to wait for new item Shared state between producer and consumer Count – the number of items written by the producer and yet to be read by the consumer Producer state: in  pointer to the next available location Consumer state: out  pointer to location of the next item

8 Producer while (true) { /* produce an item and put in nextProduced */ while (count == BUFFER_SIZE) ; // do nothing buffer [in] = nextProduced; in = (in + 1) % BUFFER_SIZE; count++; }

9 Consumer while (true) { while (count == 0) ; // do nothing nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; count--; /* consume the item in nextConsumed }

10 Race conditions Compiler translates producer’s process P instruction count++ as: R1 = count R1 = R1 +1 count = R1 Compiler translates consumer’s process C instruction count-- as: R2 = count R2 = R2 - 1 count = R2 Initially count = 5, in =12, out=7 P is scheduled to run P executes R1 = count (R1 = 5) P : executes R1 = R1 + 1 (R1 = 6) An interrupt occurs and P is suspended and C is dispatched C executes R2 = count (R2 = 5) C executes R2 = R2-1 (R2 = 4) P executes count = R1 (count = 6) P writes the new item in buffer(12); in=13 P has finished and is suspended and C is dispatched C executes count = R2 r(count = 4} C read the new item from buffer(7); out=8

11 Message passing The entities involved: Sender – process P Receiver – process Q Logical communication channel Message Issues Identification of the communicating processes (direct/indirect) Type of communication (synchronous/asynchronous) Buffering (implict/explicit)

12 Direct process identification Name the destination/source explicitely Sender (P)  send(Q, message) Receiver (Q)  receive(P,message) Alternative: receiever accepts a message from any sender: Sender (P)  send(Q, message) Receiver (Q)  receive(id,message)

13 Indirect identification – Mailboxes/Ports A mailbox/port – shared among several processes Mailboxes in user or in system address space. One or more channel may be connected to a mailbox. Each channel may be shared by a number oif processes. Sender (P)  send(mailboxA, message) Receiver (Q)  receive(mailboxA,message) Q shares its inbox with one or more processes or may have one mailbox per communication partner.

14 Sockets – communication in the Internet Two transport protocols: TCP and UDP Sockets TCP – sockets UDP sockets To send a message to a process running on a host with IP address at TCP port 80 you specify the IP anddess and the port: :80. Java sockets Connection-Oriented  TCP – sockets Socket class Connectionless  UDP sockets DatagramSocket class Multicast sockets MulticastSocket class

15 More about ports The port numbers are divided into three ranges: Well Known Ports from 0 through 1023, Registered Ports Dynamic and/or Private Ports Examples 20/tcp File Transfer [Default Data] 20/udp  File Transfer [Default Data] 21/tcp  File Transfer [Control] 21/udp  File Transfer [Control] 80/tcp  World Wide Web HTTP 80/udp  World Wide Web HTTP

16 Message passing in Mach (MAC OS X) At creation time each user process (task) is assigned two ports: Kernel  for communication with the Kernel Notify  to notify the process about the occurrence of events To create a new port a process uses: port_allocate(). The queue of messages at a port is owned by the process which created the port. To find the number of messages: port_status(). System calls for message passing: msg_send() msg_receive() msg_rpc() The system guarantees that the messages from the same sender are queued in a FIFO (First In First Out) manner. Messages from different senders could be queued in any order.

17 Synchronous/Asynchronous communication Synchronous or blocking send/receive Asynchronous (non-blocking) send/receive

18 Remote Procedure Call (RPC) Supports inter-process communication of remotely located processes and allows implementation of client-server systems (RFC 1831) Preserve the semantics of a local procedure call. To use an RPC a process may use a special service: PORTMAP or RPCBIND available at port 111. A new RPC service uses the portmapper to register. The portmapper also allows a service lookup. If the process knows the port number of the RPC it may call directly. RPC/TCP and also RPC/UDP Messages must be well-structured; contain the identification of the specific RPC are addressed to an RPC demon listening at an RPC port. A stub hides the details of the implementation of the RPC. A machine independent representation of data  external data representation standard (XDR).

19 RPC semanitcs At most once  a message is acted upon at most once. The server must keep a history of the time-stamps of all messages. Messages may arrive out of order….. What if the RPC fails? Exactly once  implement the at most once and request an acknowledgment from the server.

20 Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads

21 Single and Multithreaded Processes

22 Benefits of multithreading Responsiveness Resource Sharing Economy Takes advantage of multi-processor and multi-core architectures

23 User Threads Thread management done by user-level threads library Thread libraries: UNIX, Linux  POSIX Pthreads Microsoft Windows  Win32 threads Java threads

24 Kernel Threads Windows XP/2000 Solaris Linux Tru64 UNIX Mac OS X

25 Multithreading Models Many-to-One One-to-One Many-to-Many

26 Many-to-One Many user-level threads mapped to single kernel thread Examples: Solaris Green Threads GNU Portable Threads

27 Many-to-One

28 One-to-One Each user-level thread maps to one kernel thread Examples Windows NT/XP/2000 Linux Solaris 9 and later

29 One-to-one

30 Many-to-Many Allows a user level thread to be mapped to several kernel threads the operating system to create a sufficient number of kernel threads Examples Solaris prior to version 9 Windows NT/2000 with the ThreadFiber package

31 Many-to-Many

32 Two-level Model Similar to M:M, except that it allows a user thread to be bound to kernel thread Examples IRIX HP-UX Tru64 UNIX Solaris 8 and earlier

33 Two-level Model

34 Threading Issues Semantics of fork() and exec() system calls Thread cancellation Signal handling Thread pools Thread specific data Scheduler activations

35 Semantics of fork() and exec() Does fork() duplicate only the calling thread or all threads?

36 Thread Cancellation Terminating a thread before it has finished Two general approaches: Asynchronous cancellation terminates the target thread immediately Deferred cancellation allows the target thread to periodically check if it should be cancelled