Вы находитесь на странице: 1из 2

Brisaac Johnson

University of North Georgia


Mike Cottrell College of Business
Department of Computer Science & Information Systems
CSCI 4100 Operating Systems/File Organization (Spring 2019)
Assignment 5

1. (4 points) Race conditions are possible in many computer systems. Consider a banking
system that maintains an account balance with two functions: deposit(amount) and
withdraw(amount). These two functions are passed the amount that is to be deposited or
withdrawn from the bank account balance. Assume that a husband and wife share a bank
account. Concurrently, the husband calls the withdraw() function and the wife calls
deposit(). Describe how a race condition is possible and what might be done to prevent the
race condition from occurring.
If the balance of the Account was 500 and the husband calls withdraw(100) and the
wife calls deposit(50), the value should display 450. The two transactions are
serialized, meaning the state information of an object instance is converted into a
binary or textual form. The local value of balance for the husband would become 400.
Before he makes the transaction, the deposit(50) operation has to take place and
update the shared value of balance to 450. When we switch back to the husband and
the value of the shared balance is set to 400, one can see this value is incorrect.
2. (4 points) Describe two kernel data structures in which race conditions are possible. Be sure
to include a description of how a race condition can occur.
Example of two kernel data structures process id (pid) management system and kernel
process table. With a process id management system, it’s possible two process may be
created at the same time and there is a race condition when assigning unique pid’s.
This same race condition can occur in the kernel process table, two process are created
at the same time and there is a race in assigning them a location in the kernel process
table.
3. (4 points) Assume that a system has multiple processing cores. For each of the following
scenarios, describe which is a better locking mechanism—a spinlock or a mutex lock where
waiting processes sleep while waiting for the lock to become available:

a. The lock is to be held for a short duration. -> Spinlock, a spinlock works best in this
scenario because the lock is to be held for a short period of time and spinlocks are
ideal for when a lock is going to be held for a short time.
b. The lock is to be held for a long duration. -> Mutex Lock, a mutex lock works best
because it allows the processing core to schedule another process while the locked
process waits.
c. A thread may be put to sleep while holding the lock. -> Mutex Lock, a mutex lock
works well because you don’t want the waiting process to spin thus taking up
CPU resources while waiting for the process to wake up.
Brisaac Johnson

4. (4 points) Servers can be designed to limit the number of open connections. For example, a
server may wish to have only N socket connections at any point in time. As soon as N
connections are made, the server will not accept another incoming connection until an
existing connection is released. Explain how semaphores can be used by a server to limit the
number of concurrent connections.
A Semaphore is initialized to the number of allowable open socket connections. Once the
connection has been accepted the acquire() method is called. When the connection is
released, the release() method is called. If the system reaches the number of allowable
socket connections, subsequent calls to acquire() will block until an existing connection is
terminated and the released method is invoked.

5. (4 points) Discuss the tradeoff between fairness and throughput of operations in the readers-
writers problem. Propose a method for solving the readers-writers problem without causing
starvation.
Throughput in the readers-writers problem is increased by favoring multiple readers as
opposed to allowing a single writer to exclusively access shared values. However, favoring
readers could result in starvation of the writers. The starvation in the readers-writers problem
could be avoided by keeping timestamps associated with waiting processes. So, when the
writer finishes its tasks, it then wakes the process that has been waiting the longest. Then,
when a reader arrives and notices that another reader is accessing the database, it would
enter into the critical section only if there aren’t writers waiting.

Вам также может понравиться