Assignment 3 OS
Assignment 3 OS
1. Compare: Producer-Consumer problem with Reader Writer problem Ans: Producer-Consumer Problem: The consumer producer problem (also known as the bounded-buffer problem) is a classical example of a multi-process synchronization problem. The problem describes two processes, the producer and the consumer, who share a common, fixed-size buffer used as a queue. The producer's job is to generate a piece of data, put it into the buffer and start again. At the same time, the consumer is consuming the data (i.e., removing it from the buffer) one piece at a time. The problem is to make sure that the producer won't try to add data into the buffer if it's full and that the consumer won't try to remove data from an empty buffer. Reader-Writer Problem: An object is shared among many threads, each belonging to one of two classes: Readers: read data, never modify it Writers: read data and modify it. Using a single lock on the data object is overly restrictive Want many readers reading the object at once Allow only one writer at any point Correctness criteria Each read or write of the shared data must happen within a critical section. Guarantee mutual exclusion for writers. Allow multiple readers to execute in the critical section at once. 2. Write a solution for writer priority of reader writer problem Ans: Semaphore Solution: Writers have Priority int readcount, writecount = 0; semaphore rsem, wsem = 1; // semaphore x,y,z = 1; // void reader(){ void writer(){ while(1){ while(1){ wait(z); wait(y); wait(rsem); writecount++; wait(x); if (writecount==1) readcount++; wait(rsem); if (readcount==1) signal(y); wait(wsem); wait(wsem); signal(x); doWriting(); signal(rsem); signal(wsem);
3. Explain drawbacks of Dekkers algorithm Ans: The drawbacks of Dekkers Algorithm are: It is limited to two processes and makes use of busy waiting instead of process suspension where use of busy waiting suggests that processes should spend a minimum of time inside the critical section. Modern operating systems provide mutual exclusion primitives that are more general and flexible than Dekker's algorithm. Many modern CPUs execute their instructions in an out-of-order fashion. This algorithm won't work on SMP machines equipped with these CPUs without the use of memory barriers. In many languages, it is legal for a compiler to detect that the flag variables flag[0] and flag[1] are never accessed in the loop. It can then remove the writes to those variables from the loop, using a process called Loop-invariant code motion. It would also be possible for many compilers to detect that the turn variable is never modified by the inner loop, and perform a similar transformation, resulting in a potential infinite loop. If either of these transformations is performed, the algorithm will fail, regardless of architecture. 4. compare android OS with windows Ans: ANDROID OPERATING SYSTEM There are four officially released Versions of Android: 1. Froyo 2. Ginderbread 3. Honeycomb 4. Ice cream Sandwich 5. Jelly beans [announced recently ] PROS of Android OS: Open Source Linux based System Custom ROMs High reliability Integrated Java and Flash
Dedicated App library, i.e., Google Play Wireless app installation Good security [No antivirus needed]
application brand. 3. Largest Computing Android offers the large range of applications and smart phone application to its users. It provides specific installations and setups for the Google chromes that Microsoft windows doesnt.
Parameters
iOS 6.0 650,000+ yes limited no no yes yes no no requires iTunes yes Cydia yes drop-down pane no yes no paid apps Darwin limited via Camera Connection Kit
Android 4.1 600,000+ yes yes yes yes yes yes yes yes with Google Now yes many outlets yes drop-down pane yes yes yes Linux yes
Window s Phone 8 100,000 + yes limited expanda ble Live Tiles yes yes
Window s Phone 7.8 100,000 + yes limited expanda ble Live Tiles yes yes
Apps Multitasking Widgets Expandable storage Multi-core processors High-res displays File manager Drag and drop file management Intelligent voice assistant Sideloading apps Centralized notifications Flash support Native screenshots Offline maps Core USB Host
5. Give the solution for reader writer problem with the help of monitor and message passing.
6. compare: semaphore, msg passing & monitor SEMAPHORES MONITORS Processes need to Processes need to share Memory share Memory It is a shared variable It is a programming that can be accessed language construct anywhere in the that has protected program. data that can be accessed only by No connection process inside the between the monitor. semaphore and data being controlled. The procedures in the monitor are in Inconvenient to use. direct contact with the data. MESSAGE PASSING Processes need not share Memory. It consists of data encapsulated into messages that are transferred between the sender and intended recipient. The sender and receiver have access to the message.