1. Trang chủ
  2. » Công Nghệ Thông Tin

Lecture Operating systems: A concept-based approach (2/e): Chapter 9 - Dhananjay M. Dhamdhere

88 51 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 88
Dung lượng 1,54 MB

Nội dung

Chapter 9 - Process synchronization. This chapter discusses the synchronization requirements of some classic problems in process synchronization and discusses how they can be met by using synchronization features such as semaphores and monitors provided in programming languages and operating systems.

PROPRIETARY MATERIAL. ©  2007 The McGraw­Hill Companies, Inc. All rights reserved. No part of this PowerPoint slide  may be displayed, reproduced or distributed  in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw­Hill  for their individual course preparation. If you are a student using this PowerPoint slide, you are using it without permission.  Chapter 9: Process Synchronization Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed Slide No: 1 Copyright © 2008 Process Synchronization • Processes that work toward a common goal must coordinate their activities – Such coordination is achieved through synchronization – We discuss two kinds of synchronization defined in Chapter * Data access synchronization  Avoiding race conditions through mutual exclusion * Control synchronization  Ensuring that processes perform their actions in a desired order Chapter 9: Process Synchronization Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed SlideNo:2 Copyrightâ2008 Interacting processes Definition: Processes Pi, Pj are interacting processes if read_seti ∩ write_setj ≠ Ø or write_seti ∩ read_setj ≠ Ø, where * Read-set : Set of variables merely read by a process * Write-set : Set of variables read and written to by a process – Non-interacting processes are independent processes Chapter 9: Process Synchronization Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed SlideNo:3 Copyrightâ2008 Critical Section (CS) Definition A critical section (CS) for a data item ds is a section of code that cannot be executed concurrently with itself or with another critical section for ds * We will use a dashed rectangular box to indicate a critical section in a code segment (see next slide) • Data access synchronization – Is defined as ensuring an absence of race conditions over a shared data item ds * It is achieved by enclosing all uses of ds within critical sections Chapter 9: Process Synchronization Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed Slide No: 4 Copyright © 2008 A process having critical sections We assume a process to consist of a single infinite loop; a dashed rectangular box depicts a critical section (a) A process having many critical sections (b) A process having a single critical section Chapter 9: Process Synchronization Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed Slide No: 5 Copyright © 2008 Use of CS in airline reservation to avoid race conditions • All processes have an identical form • nextseatno is examined and incremented within a CS • Hence a race condition does not exist Chapter 9: Process Synchronization Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed Slide No: 6 Copyright © 2008 Essential properties of a CS implementation • A CS implementation must posses three properties – Correctness * At most one process can be in a CS for a data item ds at any time – Progress * When no process is in a CS for ds, a process wishing to enter a CS for ds can get in immediately  One of the processes requesting a CS on ds will definitely make progress – Bounded wait * If Pi wishes to use a CS for ds, the number of times another process can request entry to CS and get in ahead of Pi is bounded by a constant  A process is not denied entry to a CS indefinitely Chapter 9: ProcessSynchronization Dhamdhere:OperatingSystems AConceptưBasedApproach,2ed SlideNo:7 Copyrightâ2008 Busy wait A CS can be implemented as follows: while { some process is in a CS for ds } { nothing } { CS } • It causes a busy wait – Definition: Busy wait is a situation in which a process checks a condition over and over again until the condition is satisfied – A busy wait wastes CPU power Chapter 9: ProcessSynchronization Dhamdhere:OperatingSystems AConceptưBasedApproach,2ed SlideNo:8 Copyrightâ2008 Busy wait A busy wait – May lead to priority inversion * A high priority process is blocked for an I/O operation * A low priority process is scheduled and gets into a CS for ds * The high priority process becomes ready, gets scheduled and wishes to enter a CS for ds but gets into a busy wait for the CS * Both processes wait for one another indefinitely! Chapter 9: Process Synchronization Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed SlideNo:9 Copyrightâ2008 Avoiding priority inversion The Priority inheritance protocol – A low priority process holding a resource (or CS) inherits priority of the highest priority process that is waiting for the resource (or CS) * It enables the low priority process to complete use of the resource (or CS) and release it Chapter 9: Process Synchronization Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed Slide No: 10 Copyright © 2008 Process synchronization in Unix • semop is the semaphore operation – It identifies a semaphore array and issues several (subscript, op) operations on semaphores in the array – A process may wait on many semaphores simultaneously; it is activated only when waits on all semaphores are satisfied * This feature helps in avoiding deadlocks – For a process, the kernel keeps track of all of its operations on a semaphore It performs an undo on these operations when the process terminates * It helps in ensuring reliability Chapter 9: Process Synchronization Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed SlideNo:85 Copyrightâ2008 Process synchronization in Linux Linux provides two special semaphores for kernel use – Conventional semaphore, implemented with less overhead * Indivisible instructions are used to increment / decrement a semaphore’s value; it eliminates the need for a lock * The waiting process flag reduces overhead of activating processes – reader-writer semaphore to protect kernel data structures * Entry to the CS is FIFO • Futex is a user-space mutex – Represented in shared memory * System calls are made only to activate or block processes * A wait call fails when a specified amount of time is exceeded Chapter 9: Process Synchronization Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed Slide No: 86 Copyright © 2008 Process synchronization in Windows • Dispatcher objects are used for synchronization – Each process, file and event object embeds a dispatcher object * Hence synchronization can be performed on these entities • States of dispatcher objects – Non-signaled state: A process performing a wait call on it gets blocked * When the state changes to Signaled, one or more waiting processes are activated (see table) – A process can specify a time interval in a wait call • Kernel provides several synchronization locks – Spinlock, queued spinlock, fast mutex, push locks Chapter 9: Process Synchronization Dhamdhere:OperatingSystems AConceptưBasedApproach,2ed SlideNo:87 Copyrightâ2008 Windows synchronization objects A process enters the signaled state when the last thread in it terminates; all processes blocked on it are activated • An event enters the signaled state when it is set; all threads blocked on it are activated Chapter 9: Process Synchronization Dhamdhere: Operating Systems— A Concept­Based Approach, 2 ed Slide No: 88 Copyright © 2008 ... could race conditions arise on these variables? Chapter 9: Process Synchronization Dhamdhere: Operating Systems— A Concept­Based Approach,  2 ed Slide No: 12 Copyright © 2008 An attempt at signaling... sets action_aj_performed, but does not activate process P • Q: Can the race condition have another consequence? Chapter9 : ProcessSynchronization Dhamdhere: OperatingSystems AConceptưBasedApproach,2ed... conventions for shared data, queue of blocked processes and mutually exclusive operations (a dashed box) Chapter 9: Process Synchronization Dhamdhere: Operating Systems— A Concept­Based Approach,  2 ed

Ngày đăng: 30/01/2020, 02:15

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN