CS 149: Operating Systems February 10 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak www.cs.sjsu.edu/~mak.

Slides:



Advertisements
Similar presentations
Processes Management.
Advertisements

©2009 Operačné systémy Procesy. 3.2 ©2009 Operačné systémy Process in Memory.
Dr. Kalpakis CMSC 421, Operating Systems. Fall Processes.
Abhinav Kamra Computer Science, Columbia University 4.1 Operating System Concepts Silberschatz, Galvin and Gagne  2002 Chapter 4: Processes Process Concept.
Adapted from slides ©2005 Silberschatz, Galvin, and Gagne Lecture 4: Processes.
Chapter 3: Processes.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 3: Processes.
Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Silberschatz, Galvin and Gagne ©2007 Chapter 3: Processes.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Chapter 3: Processes Process Concept.
1/30/2004CSCI 315 Operating Systems Design1 Processes Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Chapter 3: Processes. Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication in Client-Server.
02/02/2004CSCI 315 Operating Systems Design1 Interprocesses Communication Notice: The slides for this lecture have been largely based on those accompanying.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 4: Processes Process Concept Process Scheduling Operations on Processes Cooperating.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Chapter 3: Processes Process Concept.
02/01/2010CSCI 315 Operating Systems Design1 Interprocess Communication Notice: The slides for this lecture have been largely based on those accompanying.
Threads© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer Science Department.
1/26/2007CSCI 315 Operating Systems Design1 Processes Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Interprocess Communication. Process Concepts Last class.
Inter-process communication
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
Chap 3 Processes-Concept. Process Concept Process – a program in execution; process execution must progress in sequential fashion A process includes:
Chapter 4: Processes Process Concept Process Scheduling Operations on Processes Cooperating Processes Inter-process Communication Communication in Client-Server.
Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication in Client-Server Systems.
CS 149: Operating Systems January 29 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Process Concept Process – a program.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 3: Processes.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 3: Processes.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
4.1 Silberschatz, Galvin and Gagne ©2003 Operating System Concepts with Java Chapter 4: Processes Process Concept Process Scheduling Operations on Processes.
AE4B33OSS Chapter 3: Processes. 3.2Silberschatz, Galvin and Gagne ©2005AE4B33OSS Chapter 3: Processes Process Concept Process Scheduling Operations on.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Outline n Process Concept n Process.
Chapter 3: Processes (6 th edition chap 4). 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
1 11/1/2015 Chapter 4: Processes l Process Concept l Process Scheduling l Operations on Processes l Cooperating Processes l Interprocess Communication.
3.1 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Interprocess Communication Processes within a system may be.
Processes. Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 3: Processes.
CS212: OPERATING SYSTEM Lecture 2: Process 1. Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-4 Process Communication Department of Computer Science and Software.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 10 Processes II Read.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 3 Operating Systems.
PREPARED BY : MAZHAR JAVED AWAN BSCS-III Process Communication & Threads 4 December 2015.
Chapter 3: Process-Concept. Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 4: Processes Process Concept Process Scheduling Operations on Processes Cooperating.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Chapter 3: Processes Process Concept.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Chapter 3: Processes Process Concept.
3.1 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Overview: Process Concept Process Scheduling Operations on Processes.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Jan 19, 2005 Chapter 3: Processes Process Concept.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 3: Processes.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Jan 19, 2005 Chapter 3: Processes Process Concept.
Chapter 3: Processes-Concept. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes-Concept Overview Process Scheduling.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 3: Processes.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Processes. Process Concept Process Scheduling Operations on Processes Interprocess Communication Communication in Client-Server Systems.
InterProcess Communication. Interprocess Communication Processes within a system may be independent or cooperating Cooperating process can affect or be.
 Process Concept  Process Scheduling  Operations on Processes  Cooperating Processes  Interprocess Communication  Communication in Client-Server.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
Chapter 4: Processes Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication in Client-Server.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
3.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Objectives To introduce the notion of a process -- a program in execution,
Chapter 3: Process-Concept. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 3: Process-Concept Process Concept Process Scheduling.
3.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Process Termination Process executes last statement and asks the operating.
4.1 Operating System Chapter 4: Processes Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Chapter 3: Processes Process Concept.
XE33OSA Chapter 3: Processes. 3.2XE33OSASilberschatz, Galvin and Gagne ©2005 Chapter 3: Processes Process Concept Process Scheduling Operations on Processes.
Chapter 4: Processes Process Concept Process Scheduling
CS 144 Advanced C++ Programming May 7 Class Meeting
Processes August 10, 2019 OS:Processes.
Presentation transcript:

CS 149: Operating Systems February 10 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 2 POSIX Threads  The POSIX standard for threads is implemented by the Pthreads package. Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc All rights reserved Actually, the PThreads function names are all in lower case: pthread_create, pthread_exit, pthread_attr_init, etc.

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 3 Thread Code Example: Parent #include char *greeting; // shared data void *runner(void *parm); // the thread int main(int argc, char *argv[]) { pthread_t tid; pthread_attr_t attr; printf("Parent: Creating child thread.\n"); pthread_attr_init(&attr); pthread_create(&tid, &attr, runner, argv[1]); printf("Parent: Waiting for child to complete.\n"); pthread_join(tid, NULL); printf("Parent: Child has completed, set greeting '%s'.\n", greeting); printf("Parent: Terminating.\n"); exit(0); } Pointer greeting is shared by the parent and child thread. Parent code. threadtest.c

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 4 Thread Code Example: Child void *runner(void *parm) { printf("Child: Started with parm '%s'.\n", parm); printf("Child: Creating greeting... "); greeting = malloc(strlen(parm) + 8); sprintf(greeting, "Hello, %s!", parm); printf("done!\n"); printf("Child: Terminating.\n"); pthread_exit(0); } Child thread. Compile and link: gcc –pthread –o threadtest threadtest.c Demo

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 5 Interprocess Communication  Processes within a system may be independent or cooperating. A cooperating process can affect or be affected by other executing processes. An independent process cannot affect or be affected by other executing processes.  Reasons for processes to cooperate: Information sharing Computation speedup Modularity Convenience

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 6 Interprocess Communication, cont’d  Interprocess communication (IPC) Needed by cooperating processes. Exchange data and information.  Two models of IPC: Shared memory Message passing

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 7 Interprocess Communication, cont’d Message passingShared memory Operating Systems Concepts, 9 th edition Silberschatz, Galvin, and Gagne (c) 2013 John Wiley & Sons. All rights reserved

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 8 IPC: Shared Memory  Establish a shared-memory region. Once established, all accesses to the region are treated the same as regular memory accesses. No OS kernel intervention required to communicate. Allows maximum speed and convenience. Faster than message passing.  A shared-memory region typically resides in the address space of the process that created it. Any other process that wishes to communicate using this region must attach the region to its address space.

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 9 IPC: Shared Memory, cont’d  With shared memory, cooperating processes: Agree to override the protection mechanisms of the OS that prevent one process from addressing another process’s memory. Exchange data by reading and writing in the shared-memory region.  Cooperating processes must arrange among themselves not to step on each other. Don’t write simultaneously to the same location.

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 10 Shared Memory: Producer-Consumer  A “producer” process can pass data to a “consumer” process using shared memory.  Use the POSIX API for shared memory. This API organizes shared memory as memory-mapped files, which associate the shared-memory region with a file. The shared memory region must have a name. It must be linked against librt real-time library using the gcc flag -lrt

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 11 Shared Memory: Producer #include int main(int argc, char *args[]) { const int SIZE = 4096; // size of shared memory object const char *NAME = "OS"; // name of shared memory object int shm_fd; // shared memory file descriptor void *ptr; // pointer to shared memory object // Create shared memory object and configure its size. shm_fd = shm_open(NAME, O_CREAT | O_RDWR, 0666); ftruncate(shm_fd, SIZE); // Memory map the shared memory object. ptr = mmap(0, SIZE, PROT_WRITE, MAP_SHARED, shm_fd, 0); // Write to the shared memory object. sprintf(ptr, "%s", args[1]); return 0; } producer.c Compile: gcc –lrt –o producer producer.c

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 12 Shared Memory: Consumer #include int main() { const int SIZE = 4096; // size of shared memory object const char *NAME = "OS"; // name of shared memory object int shm_fd; // shared memory file descriptor void *ptr; // pointer to shared memory object // Open the shared memory object. shm_fd = shm_open(NAME, O_RDONLY, 0666); // Memory map the shared memory object. ptr = mmap(0, SIZE, PROT_READ, MAP_SHARED, shm_fd, 0); // Read from the shared memory object and then remove it. printf("%s\n", (char *) ptr); shm_unlink(NAME); return 0; } consumer.c Compile: gcc –lrt –o consumer consumer.c

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 13 Shared Memory: Producer-Consumer, cont’d  A more general producer-consumer model: The producer process repeatedly adds data to the shared memory. The consumer process repeatedly retrieves data from the shared memory.  Both processes run concurrently.  In order for this to work, both processes must be synchronized. What could happen if they’re not synchronized?

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 14 Interprocess Communication, cont’d Message passingShared memory Operating Systems Concepts, 9 th edition Silberschatz, Galvin, and Gagne (c) 2013 John Wiley & Sons. All rights reserved

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 15 IPC: Message Passing  Useful for exchanging small amounts of data.  Easier to implement than shared memory. No conflicts involving one process stepping on the other.  Slower than shared memory. Implemented with system calls. Requires OS kernel intervention.

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 16 IPC: Message Passing, cont’d  Cooperating processes can communicate and synchronize their actions without sharing the same address space. No shared memory regions.  Particularly useful in a distributed environment. Communicating processes do not necessarily have to know where the other processes reside.

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 17 IPC: Message Passing, cont’d  Messages can be fixed or variable length.  Fixed length: Easier system-level implementation, but makes programming more difficult.  Variable length: Harder system-level implementation, but simpler programming.

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 18 Message Passing: Direct Communication  Cooperating processes must be able to refer to each other by their names.  The processes must establish a communications link. Capacity? Unidirectional? Bidirectional?

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 19 Message Passing: Direct Communication, cont’d  Send and receive primitives: send(P, message) sends a message to process P. receive(Q, message) receives a message from process Q. receive(id, message) receives a message from any process, as identified by the process id.

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 20 Message Passing: Indirect Communication  Send and receive messages from mailboxes or ports shared by cooperating processes.  Send and receive primitives: send(A, message) sends a message to mailbox A. receive(A, message) receives a message from mailbox A.

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 21 Message Synchronization  Message passing may be blocking or nonblocking, AKA synchronous and asynchronous, respectively.

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 22 Message Synchronization, cont’d  Blocking send The sending process is blocked until the message is received.  Nonblocking send The sending process sends the message and continues operating.  Blocking receive The receiver blocks until a message is available.  Nonblocking receive The receive either retrieves a message or a null.

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 23 Client-Server Communications: Sockets  A socket is a communications endpoint.  Two processes can communicate over a network using a pair of sockets, one per process.  A socket has an IP address and a port number. Silberschatz, Galvin, and Gagne Operating Systems Concepts, 8 th edition (c) 2012 John Wiley & Sons. All rights reserved

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 24 Client-Server Communications: RPC  Remote Procedure Calls (RPC) abstract procedure calls between processes on networked systems.  Stub: Client-side proxy for the actual procedure that resides on the server.  The client-side stub locates the server and marshals the parameters. Convert the parameter values to a form that can be transmitted over the network.

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 25 Client-Server Communications: RPC  The server-side skeleton receives this message, unmarshals the parameters, and performs the procedure on the server.

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 26 Remote Procedure Calls, cont’d  Marshalling and unmarshalling Silberschatz, Galvin, and Gagne Operating Systems Concepts, 8 th edition (c) 2012 John Wiley & Sons. All rights reserved

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 27 Client-Server Communications: Pipes  Pipes are communications conduits for cooperating processes.  A pipe is a special type of file accessed using ordinary read() and write() system calls.  Typically, a parent process creates a pipe and then forks a child process. The parent process makes the pipe available to the child process to use in order to communicate with the child.

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 28 UNIX Pipe Example  Create an ordinary pipe using the system call pipe(int fd[]) where fd is an array of two file descriptors. fd[0] : File descriptor of the read end of the pipe fd[1] : File descriptor of the write end of the pipe Parent Child fd[0] read fd[1] write Pipe x Not used x

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 29 Pipe: Example C Code #include #define BUFFER_SIZE 25 #define READ_END 0 #define WRITE_END 1 int main(void) { char write_msg[BUFFER_SIZE] = "Hello, my child"; char read_msg[BUFFER_SIZE]; pid_t pid; // child process id int fd[2]; // file descriptors for the pipe if (pipe(fd) == -1) { fprintf(stderr,"Pipe failed"); return 1; }... } Create the pipe. pipe.c Compile: gcc –o pipe pipe.c

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 30 Pipe: Example C Code, cont’d int main(void) {... pid = fork(); if (pid > 0) { // Close the unused READ end of the pipe. close(fd[READ_END]); // Write to the WRITE end of the pipe. write(fd[WRITE_END], write_msg, strlen(write_msg)+1); printf("Parent: Wrote '%s' to the pipe.\n", write_msg); // Close the WRITE end of the pipe. close(fd[WRITE_END]); }... } Parent process

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 31 Pipe: Example C Code, cont’d if (pid > 0) {... } else if (pid == 0) { // Close the unused WRITE end of the pipe. close(fd[WRITE_END]); // Read from the READ end of the pipe. read(fd[READ_END], read_msg, BUFFER_SIZE); printf("Child: Read '%s' from the pipe.\n", read_msg); // Close the READ end of the pipe. close(fd[READ_END]); }... return 0; } Child process Demo

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 32 Process Synchronization  Multiple cooperating processes executing concurrently must synchronize their operations.  Share information. Shared memory or message passing.  Don’t step on each other. Example: Don’t have multiple processes simultaneously modify the same memory location.

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 33 Process Synchronization, cont’d  Properly sequence their operations.  One process depends on another. Example: Process B depends on output generated by Process A. Therefore, Process B must wait until Process A has produced its output.

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 34 Race Condition  A race condition occurs when Multiple processes access and modify some shared data. The final result depends on the order that the processes modified the data.  A very bad situation! Results are often unpredictable and unrepeatable. Extremely hard to debug. Must avoid!

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 35 Race Condition Example  Suppose variable count is shared by two processes.  count++ can be implemented as: register1  count register1  register1 + 1 count  register1  count-- can be implemented as: register2  count register2  register2 – 1 count  register2  Suppose the value of count is 5 and that process P1 executes count++ at the same time that process P2 executes count--.

36 Race Condition Example, cont’d ProcessOperationResult P1register1  countregister1 = 5 P1register1  register1 + 1register1 = 6 P2register2  countregister2 = 5 P2register2  register2 - 1register2 = 4 P1count  register1count = 6 P2count  register2count = 4 count++ register1  count register1  register1 + 1 count  register1 count-- register2  count register2  register2 – 1 count  register2  Whether the value of count ends up as 4 or 6 depends on the order of execution of the last two instructions.

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 37 Mutual Exclusion  One way to avoid race conditions is to prevent more than one process from reading and writing the shared data at the same time.  This is called mutual exclusion.  Operating systems provide different primitives to enforce mutual exclusion.

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 38 Critical Region  A critical region (AKA critical section) is the part of a process’s code that operates on some shared data. NOTE: A critical region is code, not data.  We must prevent two processes from being in their critical regions for the same shared data at the same time.

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 39 To Prevent Race Conditions  Mutual exclusion: No two processes may be simultaneously inside their critical regions for the same shared data.  Progress: No process running outside its critical region may block other processes.  Bounded waiting: No process should have to wait forever to enter its critical region.

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 40 To Prevent Race Conditions, cont’d  When a process is in its critical region, other processes must be blocked from entering their critical regions.  No assumptions may be made about the number of CPUs or their speeds.

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 41 Critical Region, cont’d Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc All rights reserved

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 42 Critical Region vs. Shared Memory  Do not confuse critical region with the shared data. Two (or more) processes can share a piece of data.  The code in a process that accesses that shared data is that process’s critical region with respect to that shared data.

Computer Science Dept. Spring 2015: February 10 CS 149: Operating Systems © R. Mak 43 Critical Region, cont’d  The code in the critical region of each process can be different from the code in the critical region of another process.  What the code in the critical regions have in common is that they access the same shared piece of data.  Another piece of shared data would be associated with another set of critical regions within the processes that access that data.