operating systems chapter 5

Ace your homework & exams now with Quizwiz!

How does the Peterson's Solution solve the three Critical Section requirements?

1. Mutual exclusion is preservedPienters CS only if: either flag[j] = false or turn = i 2. Progress requirement is satisfied 3. Bounded-waiting requirement is met

Bounded Waiting

A bound must exist on the number of times that other processes are allowed to enter their critical sections after a process has made a request to enter its critical section and before that request is granted Assume that each process executes at a nonzero speed No assumption concerning relative speed of thenprocesses

Monitors

A high-level abstraction that provides a convenient and effective mechanism for process synchronization Abstract data type, internal variables only accessible by code within the procedure Only one process may be active within the monitor at a time But not powerful enough to model some synchronization schemes

How to handle dining philosophers problem

Allow at most 4 philosophers to be sitting simultaneously at the table. Allow a philosopher to pick up the forks only if both are available (picking must be done in a critical section. Use an asymmetric solution -- an odd-numbered philosopher picks up first the left chopstick and then the right chopstick. Even-numbered philosopher picks up first the right chopstick and then the left chopstick.

A solution to the critical-section problem must satisfy the following three requirements. What is the third?:

Bounded waiting. There exists a bound, or limit, on the number of times that other processes are allowed to enter their critical sections after a process has made a request to enter its critical section and before that request is granted.

Progress

If no process is executing in its critical section and there exist some processes that wish to enter their critical section, then the selection of the processes that will enter the critical section next cannot be postponed indefinitely

Mutual Exclusion

If process Piis executing in its critical section, then no other processes can be executing in their critical sections

busy waiting

While a process is in its critical section, any other process that tries to enter its critical section must loop continuously in the call to acquire().

Peterson's Solution

______________ is a critical problem solution that restricts two processes that alternate execution between their critical sections and remainder sections. The processes are numbered P0 and P1. For convenience, when presenting Pi, we use Pj to denote the other process; that is, j equals 1 − i.

How mutex lock works

a process must acquire the lock before entering a critical section; it releases the lock when it exits the critical section. The acquire()function acquires the lock, and the release() function releases the lock. it has a boolean variable available whose value indicates if the lock is available or not. If the lock is available, a call to acquire() succeeds, and the lock is then considered unavailable. A process that attempts to acquire an unavailable lock is blocked until the lock is released.

cooperating process

a process that can affect or be affected by other processes executing in the system. It can either directly share a logical address space (that is, both code and data) or be allowed to share data only through files or messages.

spinlock

a type of mutex lock that is actually a busy waiting, because the process "spins" while waiting for the lock to become available. This continual looping is clearly a problem in a real multiprogramming system, where a single CPU is shared among many processes. Busy waiting wastes CPU cycles that some other process might be able to use productively

preemptive kernel

allows a process to be preempted while it is running in kernel mode.

How counting semaphore works

can be used to control access to a given resource consisting of a finite number of instances. The semaphore is initialized to the number of resources available. Each process that wishes to use a resource performs a wait() operation on the semaphore (thereby decrementing the count). When a process releases a resource, it performs a signal() operation (incrementing the count). When the count for the semaphore goes to 0, all resources are being used. After that, processes that wish to use a resource will block until the count becomes greater than 0.

Uniprocessors

could disable interrupts (too inefficient for multiprocessor systems) Currently running code would execute without preemption. Operating systems using this not broadly scalable

Concurrent access to shared data may result in

data inconsistency

nonpreemptive kernel

does not allow a process running in kernel mode to be preempted; a kernel-mode process will run until it exits kernel mode, blocks, or voluntarily yields control of the CPU.

nonpreemptive kernel is essentially free

of race conditions in kernel mode

What are the two general approaches used to handle critical sections in operating systems?

preemptive kernels and preemptive kernels

locking

protecting critical regions via locks

To prevent race condition

we need to ensure that only one process at a time can be manipulating the variable counter. To make such a guarantee, we require that the processes be synchronized in some way.

exit section

The section of code following a critical section.

The Person's solution is broken into

A two process solution: Assume that the load and store machine-language instructions are atomic; that is, cannot be interrupted

Reader

A producer who simply wants to read the database

race condition

A situation where several processes access and manipulate the same data concurrently and the outcome of the execution depends on the particular order in which the access takes place.

process synchronization

Coordination among cooperating processes

critical section

Each process has a segment of code in which the process may be changing common variables, updating a table, writing a file, and so on.

Dining-Philosophers Problem

Five philosophers spend their lives thinking, eating, only five chopsticks The idea that resources must be shared among several processes in a deadlock and starvation free manner.

Readers-Writers Problem

Imagine a database shared among several processes. If multiple readers read the database there is no problem, but if two writers or a writer and a reader try and access it at the same time, big problems can occur. To combat this problem, the writers have exclusive access to the shared database while writing to the database. First variation - no reader kept waiting unless writer has permission to use shared object Second variation - once writer is ready, it performs the write ASAP Both may have starvation leading to even more variations Problem is solved on some systems by kernel providing reader-writer locks

Problems with semaphore operations

Incorrect use of semaphore operations: signal (mutex) .... wait (mutex)l wait (mutex) ... wait (mutex) Omitting of wait (mutex) or signal (mutex) (or both) Deadlock and starvation are possible.

Starvation

Indefinite blocking. A process may never be removed from the semaphore queue in which it is suspended

critical-section problem

Is to design a protocol that the processes can use to cooperate. Each process must request permission to enter its critical section. The section of code implementing this request is the entry section.

Code that is subject to race conditions

Kernal code data structures and all their types which include structures for maintaining memory allocation, for maintaining process lists, and for interrupt handling.

Processes can execute concurrently and

May be interrupted at any time, partially completing execution

A solution to the critical-section problem must satisfy the following three requirements. What is the first?:

Mutual exclusion. If process Pi is executing in its critical section, then no other processes can be executing in their critical sections.

Bounded-Buffer Problem

N buffers, each can hold one item Semaphore mutex initialized to the value 1 Semaphore full initialized to the value 0 Semaphore empty initialized to the value N. We can interpret this code as the producer producing full buffers for the consumer or as the consumer producing empty buffers for the producer.

The important feature of critical section is that

No other process is allowed to execute in its critical section. That is, no two processes are executing in their critical sections at the same time.

Writer

Producer who writes to the database

A solution to the critical-section problem must satisfy the following three requirements. What is the second?:

Progress. If no process is executing in its critical section and some processes wish to enter their critical sections, then only those processes that are not executing in their remainder sections can participate in deciding which will enter its critical section next, and this selection cannot be postponed indefinitely.

Priority Inversion

Scheduling problem when lower-priority process holds a lock needed by higher-priority process. Solved via priority-inheritance protocol

entry section

Section of code requesting permission to enter the critical section

mutex lock

Software tool that is used to solve critical section problem. It stands for mutual exclusion and is the simplest of these tools.

semaphore

Synchronization tool that does not require busy waiting. more sophisticated ways (than Mutex locks) for process to synchronize their activities.

Compare-and-swap

The compare and swap() instruction, in contrast to the test and set() instruction, operates on three operands; The operand value is set to new value only if the expression (*value == exected) is true. Regardless, compare and swap() always returns the original value of the variable value.

Test-And-Set

The important characteristic of this instruction is that it is executed atomically. Thus, if two test and set() instructions are executed simultaneously (each on a different CPU), they will be executed sequentially in some arbitrary order. If the machine supports the test and set() instruction, then we can implement mutual exclusion by declaring a boolean variable lock, initialized to false.

disadvantage of implementing mutex lock

The main disadvantage of the implementation given here is that it requires busy waiting.

remainder section

The remaining code

What are the downsides to preemptive kernel?

They are not free from race conditions and must be designed carefully. They are also difficult to design for SMP architectures, since in these environments it is possible for two kernel-mode processes to run simultaneously on different processors.

deadlock

Two or more processes are waiting indefinitely for an event that can be caused by only one of the waiting processes. Can cause starvation and priority inversion

The two processes of the Peterson's Solution share two variables:

int turn; Boolean flag[2] The variable turn indicates whose turn it is to enter the critical section The flagarray is used to indicate if a process is ready to enter the critical section. flag[i] = trueimplies that process Pi is ready!

binary semaphore

integer value can range only between 0 and 1 (same as mutex lock)

counting semaphore

integer value can range over an unrestricted domain

sempahore S

is an integer variable that, apart from initialization, is accessed only through two standard atomic operations: wait() and signal(). All modifications to the integer value of the semaphore in the wait() and signal() operations must be executed indivisibly. That is, when one process modifies the semaphore value, no other process can simultaneously modify that same semaphore value. In addition, in the case of wait(S), the testing of the integer value of S (S ≤ 0), as well as its possible modification (S--), must be executed without interruption.

What are the upsides to preemptive kernel

may be more responsive, since there is less risk that a kernel-mode process will run for an arbitrarily long period before relinquishing the processor to waiting processes. (Of course, this risk can also be minimized by designing kernel code that does not behave in this way.) Furthermore, it is more suitable for real-time programming, as it will allow a real-time process to preempt a process currently running in the kernel.

Maintaining data consistency requires

mechanisms to ensure the orderly execution of cooperating processes

Spinlocks advantage

no context switch is required when a process must wait on a lock, and a context switch may take considerable time. Thus, when locks are expected to be held for short times, spinlocks are useful. They are often employed on multiprocessor systems where one thread can "spin" on one processor while another thread performs its critical section on another processor.

Atomic

non-interruptible


Related study sets

Microbiology Unit 2: Mycology (Exam 1)

View Set

Module 3: Learning and Development

View Set

2.3 Financial Markets Instruments, Econ Old Exam Midterm 1, M&B: Ch 3 TB, Econ Chapter 5,6, & 7, CH. 2: MONEY & PAYMENTS SYSTEM, Chapter 3, Econ 3229 practice test 1, Chapter 6, Exam 2 Chapter 7, Money and Banking chapter 6

View Set

29 Art History: Impressionism, 28 Art History: Romanticism, Neoclassical, Neoclassical, 26 Art History: 18th Century Art in Europe, 25 Art History: Rococo Style, 23 Art History: Native American Art in North America, Native American Art in North Ameri...

View Set

Chapter 8 End of Book Questions CSCI 290

View Set

Shock, trauma, burns, hemodynamics,

View Set

6th Grade Language Arts 2nd Semester

View Set