Question |
Max. |
Current |
True/False |
10 pts. |
|
Short Questions 1-5 |
15 pts. |
|
Short Questions 5-10 |
15 pts. |
|
11, |
10 pts. |
|
12. |
10 pts. |
|
13. |
15 pts. |
|
14. |
15 pts. |
|
15. |
10 pts |
|
Total: |
2. (3 pts.) Explain how the quantum length can affect the priority
of a processes in modern operating systems and how this is going to
improve the execution of the applications.
3. (3 pts.) a) Write the code for spinlock/unlock? b) What problems
we may encounter if we remove the thread_yield() instruction?
4. (3 pts.) Enumerate the checks that the kernel does during the system call open(filename, mode)
5. (3 pts.) What are the steps for processing an interrupt.
6. (3 pts.) Explain why it is a good idea to choose a quantum that
is longer than the average CPU burst.
7. (3 pts.) Mark the "C" expressions that are quivalent to a[i]. The type of a[i] is <type of a[0]>
Expression | Equivalent to a[i]. Yes or Not |
a + i | |
a + i * sizeof( <type of a[0]>) | |
&a + i | |
*(a + i) | |
*(a[0] + i) | |
*(&a[0] + i) | |
*(&a[i]) | |
&a[i] | |
*(<type of a[0]> *) ((char *) &a[0] + i ) | |
*(<type of a[0]> *) ((char *)&a[0] + i * sizeof(a[0])) |
8. (3 pts.) What are the advantages and disadvantages of using threads vs. using processes?
9. (3 pts.) What is the problem of having long critical sections?
10. (3 pts.) Explain step by step the life cycle of a program from
editing to running.
11. (10 pts.) Implement the function char
*strstr(const char *haystack, const char *needle). The
strstr() function finds the first occurrence of the
substring needle in the
string haystack and returns
a pointer to the beginning of the substring. The terminating `\0'
characters are not compared. |
char *strstr(const char *haystack, const char *needle) |
12. (10 pts.) Implement the class Array3D of type double that creates a 3D array of 3 dimensions m x n x r as indicated in the constructor. Also implement the function getElementAt and setElementAt that gets and sets the element at this location. Base your implementation in the array of pointers to rows that we covered in class. |
class Array3D { // Add any variables you need
double getElementAt( int m, int n,
int r);
{
} void
|
15. (10 pts) Assume that there are n threads t0,
t1, t2... tn-1 where the ith thread
needs to lock two mutexes mutexi and mutex(i+1)%1 to do an operation as
shown in the code below. Assuming that n=6, a) Using a time diagram (like the ones we use in class that shows multiple threads) show the sequence of events that can lead to a deadlock. b) Represent this deadlock in a graph. c) Modify the code below so the deadlock can be prevented. |
|
15. (10 pts) Assume that there are n threads t0,
t1, t2... tn-1 where the ith thread
needs to lock two mutexes mutexi and mutex(i+1)%1 to do an operation as
shown in the code below. Assuming that n=6, a) Using a time diagram (like the ones we use in class that shows multiple threads) show the sequence of events that can lead to a deadlock. b) Represent this deadlock in a graph. c) Modify the code below so the deadlock can be prevented. |
|
15. (10 pts) Assume that there are n threads t0,
t1, t2... tn-1 where the ith thread
needs to lock two mutexes mutexi and mutex(i+1)%1
to do an operation as shown in the code below. Assuming that n=6, a) Using a time diagram (like the ones we use in class that shows multiple threads) show the sequence of events that can lead to a deadlock. b) Represent this deadlock in a graph. c) Write a second version of thread_function where the deadlock is prevented. |
|
int main( int argc, char ** argv)
{
}
14. (15 pts.) Write a class AlertTable that implements two methods: void insert(key, data) andchar * remove(key). The method insert(key,data) will add the pair (key,data) to the table and will wakeup any thread calling remove(key) that is waiting for that specific key. The method remove(key) will check if there is an entry already with that key in the table and it will remove it if it is found. Otherwise, it will wait until that entry is inserted. remove(key) will return the data that corresponds to that key. If two remove(key) calls wait simultaneously for the same key, the oldest one will wakeup after the first insert call for that key and the newest one will wakeup after a subsequent insertcall with the same key. Implement the table as a list, array, hash table or in any way you want. There is no limit in the size of the table. The type of the key is char *. |
|
15. (10 pts) Assume that there are n threads t0,
t1, t2... tn-1 where the ith thread
needs to lock two mutexes mutexi and mutex(i+1)%1
to do an operation as shown in the code below. Assuming that n=6, a) Using a time diagram (like the ones we use in class that shows multiple threads) show the sequence of events that can lead to a deadlock. b) Represent this deadlock in a graph. c) Write a second version of thread_function where the deadlock is prevented. |
|