Assignment 3 OS
-
Upload
valerie-thompson -
Category
Documents
-
view
217 -
download
0
Transcript of Assignment 3 OS
-
7/29/2019 Assignment 3 OS
1/5
ASSIGNMENT-3
1. Compare: Producer-Consumer problem with Reader Writer problemAns:
Producer-Consumer Problem:
The consumer producer problem (also known as the bounded-buffer problem) is aclassical example of a multi-process synchronization problem.
The problem describes two processes, the producer and the consumer, who share acommon, 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 problemAns: Semaphore Solution: Writers have Priority
int readcount, writecount = 0;
semaphore rsem, wsem = 1; //
semaphore x,y,z = 1; //
void reader(){
while(1){wait(z);
wait(rsem);
wait(x);
readcount++;
if (readcount==1)
wait(wsem);
signal(x);
signal(rsem);
void writer(){
while(1){wait(y);
writecount++;
if (writecount==1)
wait(rsem);
signal(y);
wait(wsem);
doWriting();
signal(wsem);
http://en.wikipedia.org/wiki/Process_(computing)http://en.wikipedia.org/wiki/Synchronization_(computer_science)http://en.wikipedia.org/wiki/Buffer_(computer_science)http://en.wikipedia.org/wiki/Queue_(data_structure)http://en.wikipedia.org/wiki/Queue_(data_structure)http://en.wikipedia.org/wiki/Buffer_(computer_science)http://en.wikipedia.org/wiki/Synchronization_(computer_science)http://en.wikipedia.org/wiki/Process_(computing) -
7/29/2019 Assignment 3 OS
2/5
signal(z);
doReading();
wait(x);
readcount--;
if (readcount==0)
signal(wsem);
signal(x);
}
}
wait(y);
writecount--;
if (writecount==0)
signal(rsem);
signal(y);
}
}
3. Explain drawbacks of Dekkers algorithmAns: The drawbacks ofDekkers Algorithm are:
It is limited to two processes and makes use ofbusy waiting instead of processsuspension 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 generaland flexible than Dekker's algorithm.
Many modern CPUs execute their instructions in an out-of-order fashion. This algorithmwon't work on SMP machines equipped with these CPUs without the use ofmemory
barriers.
In many languages, it is legal for a compiler to detect that the flag variablesflag[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 ofarchitecture.
4. compare android OS with windowsAns: ANDROID OPERATING SYSTEM
There are four officially released Versions of Android:
1. Froyo2. Ginderbread3. Honeycomb4.
Ice cream Sandwich5. Jelly beans [announced recently ]
PROS of Android OS:
Open Source Linux based System Custom ROMs High reliability Integrated Java and Flash
http://en.wikipedia.org/wiki/Busy_waitinghttp://en.wikipedia.org/wiki/CPUhttp://en.wikipedia.org/wiki/Symmetric_multiprocessinghttp://en.wikipedia.org/wiki/Memory_barrierhttp://en.wikipedia.org/wiki/Memory_barrierhttp://en.wikipedia.org/wiki/Loop-invariant_code_motionhttp://en.wikipedia.org/wiki/Infinite_loophttp://en.wikipedia.org/wiki/Infinite_loophttp://www.latesthub.org/tag/ice-cream-sandwichhttp://www.latesthub.org/tag/ice-cream-sandwichhttp://en.wikipedia.org/wiki/Infinite_loophttp://en.wikipedia.org/wiki/Infinite_loophttp://en.wikipedia.org/wiki/Loop-invariant_code_motionhttp://en.wikipedia.org/wiki/Memory_barrierhttp://en.wikipedia.org/wiki/Memory_barrierhttp://en.wikipedia.org/wiki/Symmetric_multiprocessinghttp://en.wikipedia.org/wiki/CPUhttp://en.wikipedia.org/wiki/Busy_waiting -
7/29/2019 Assignment 3 OS
3/5
Dedicated App library, i.e., Google Play Wireless app installation Good security [No antivirus needed]
Cons of Android OS:
Still Under Development
WINDOWS OPERATING SYSTEM
Windows is a very old operating system since year 1985. Windows 1 was the first
operating system by Microsoft, after then they released many updated version of Windows like:
Windows 95 [year - 1995] Windows 98 [year - 1998] Windows 2000 [year - 2000] Windows XP [2001] Windows Vista [year - 2006] Windows 7 [year - 2009] Windows 8 [year - 2012]
Pros of Windows:
Large user baseBillion of peoples are used to Windows, so there are manyprograms for various fields over internet.
Better User InterfaceIt takes less time for a newbie to learn windowsfunctioning.
Its an old operating system, so large amount of fixes for various bugs will beavailable easily over internet.
Cons of Windows:
Not open source [so you need to buy license] Less secured as compared to Linux , you need an external antivirus to secure
windows
From Windows 95 to windows 7, Microsoft fixed many bugs and improved a lotbut still it is not as reliable as linux is.
Both of the operating system is best for the mobile and pc users but there are some factorsthat can distinguish android from the windows.
1. GadgetsWindows does not have the wide range of the Google gadgets that android provide to its
user, more specifically mobile users.
2. PricingAndroid is expensive than the pure licensed window operating system by Microsoft
because of the additional feature and compatibility with almost every hardware and software
http://www.latesthub.org/what-is-windows-8-advantages/7659http://www.latesthub.org/what-is-windows-8-advantages/7659 -
7/29/2019 Assignment 3 OS
4/5
application brand.
3. Largest ComputingAndroid 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.
iOS
6.0
Android
4.1
Window
s Phone
8
Window
s Phone
7.8
Apps 650,000+ 600,000+100,000
+
100,000
+
Multitaskingyes
limitedyes
yes
limited
yes
limited
Widgets no yesexpandable
Live Tiles
expandable
Live Tiles
Expandable storage no yes yes yes
Multi-core
processorsyes yes yes yes
High-res displays yes yes yes yes
File manager no yes no no
Drag and drop file
management
no
requires iTunes
yesno
requires Zune
no
requires ZuneIntelligent voice
assistantyes
yes
with Google
Now
no no
Sideloading apps Cydiayes
many outletsno no
Centralized
notifications
yes
drop-down pane
yes
drop-down
pane
no no
Flash support no yes ? ?
Native screenshots yes yes no no
Offline mapsno
paid appsyes yes
no
only Lumias
Core Darwin LinuxWindow
s NT
Window
s CE 7
USB Host
limited
via Camera
Connection Kit
yes ? ?
Parameters
-
7/29/2019 Assignment 3 OS
5/5
5. Give the solution for reader writer problem with the help of monitor and messagepassing.
6. compare: semaphore, msg passing & monitorSEMAPHORES
Processes need toshare Memory
It is a shared variablethat can be accessedanywhere in the
program.
No connectionbetween the
semaphore and data
being controlled.
Inconvenient to use.
MONITORS
Processes need toshare Memory
It is a programminglanguage constructthat has protected
data that can be
accessed only by
process inside the
monitor.
The procedures inthe monitor are in
direct contact with
the data.
MESSAGE PASSING
Processes neednot share
Memory.
It consists of dataencapsulated intomessages that are
transferred
between the
sender and
intended recipient.
The sender andreceiver have
access to the
message.