Sie sind auf Seite 1von 2

Systems Programming Study Guide

Let’s try to make this as robust as possible, so add whatever you can!

Deadlock
There are four necessary conditions for deadlock to occur:
1) Mutual Exclusion condition: a resource that cannot be used by more than one thread at a
time
2) Hold and Wait condition: Threads already holding resources may request new resources
3) No preemption condition: No resource can be forcibly removed from a thread holding it,
resources can only be removed by explicit action of the thread
4) Circular Wait condition: Two or more threads form a circular chain where each thread waits
for a resource that the next thread in the chain holds.

Shallow Copy vs. Deep Copy


-In a shallow copy, object B is assigned to the same address block as object A. They both share
some data, so modifying one may modify the other.
Advantages of Shallow Copy: Execution speed is fast, and does not depend on the size of the data
-In a deep copy, data is actually copied over from object A to object B. They are separate from
each other, yet hold the same data.
Advantages of Deep Copy: Objects A and B do not depend on each other
Disadvantage of Deep Copy: Execution speed is slower

Locality
Temporal locality: if at one point in time a particular memory location is referenced, then it
is likely that the same location will be referenced again in the near future. There is a temporal
proximity between the adjacent references to the same memory location. In this case it is
common to make efforts to store a copy of the referenced data in special memory storage,
which can be accessed faster. Temporal locality is a very special case of the spatial locality,
namely when the prospective location is identical to the present location.
Spatial locality: if a particular memory location is referenced at a particular time, then it is likely
that nearby memory locations will be referenced in the near future. In this case it is common
to attempt to guess the size and shape of the area around the current reference for which it is
worthwhile to prepare faster access.

Semaphores vs Mutex
A mutex is essentially the same thing as a binary semaphore, and sometimes uses the same
basic implementation. However, the term "mutex" is used to describe a construct which
prevents two processes from executing the same piece of code, or accessing the same data, at
the same time. The term "binary semaphore" is used to describe a construct which limits access
to a single resource.
In many cases a mutex has a concept of an "owner": the process which locked the mutex is the
only process allowed to unlock it. In contrast, semaphores generally do not have this restriction,
something the producer-consumer example above depends upon.

Das könnte Ihnen auch gefallen