Midterm Exam

1. Process Creation

How is a new process created? Select all that apply.

Via fork Via exec Via fork followed by exec Via exec followed by fork Via exec or fork followed by exec Via fork or fork followed by exec None of the above All of the above

fork The operating system will create a new process that is exactly the same as the parent process.

exec exec will replace the contents of the currently running process with the information from a program binary.

2. Multi-Threading and 1 CPU

Is there a benefit of multithreading on 1 CPU?

Yes No

Yes. The main reason is to hide the latency associated with code that blocks processing (such as a disk I/O request).

3. Critical Section

In the (pseudo) code segments for the producer code and consumer code, mark and explain all the lines where there are errors.

Global Section

int in, out, buffer[BUFFERSIZE];
mutex_t m;
cond_var_t not_empty, not_full;

Producer Code

1.    while (more_to_produce) {
2.      mutex_lock(&m);
3.      if (out == (in + 1) % BUFFERSIZE)) // buffer full 
4.         condition_wait(&not_full);
5.    add_item(buffer[in]); // add item
6.      in = (in + 1) % BUFFERSIZE 
7.       cond_broadcast(&not_empty);
8.             
9. } // end producer code

Consumer Code

1.    while (more_to_consume) {
2.    mutex_lock(&m);
3.    if (out == in) // buffer empty 
4.      condition_wait(&not_empty);
5.    remove_item(out);
6.    out = (out + 1) % BUFFERSIZE; 
7.    condition_signal(&not_empty);
8.          
9. } // end consumer code

4. Calendar Critical Section

A shared calendar supports three types of operations for reservations: read cancel enter

Requests for cancellations should have priority above reads, who in turn have priority over new updates.

In pseudocode, write the critical section enter/exit code for the read operation.

mutex_lock(&m);

mutex_unloc(&m);

5. Signals

If the kernel cannot see user-level signal masks, then how is a signal delivered to a user-level thread (where the signal can be handled)?

Solution Recall that all signals are intercepted by a user-level threading library handler, and the user-level threading library installs a handler. This handler determines which user-level thread, if any, the signal be delivered to, and then it takes the appropriate steps to deliver the signal.

Note: If all user-level threads have the signal mask disabled and the kernel-level signal mask is updated, then and the signal remains pending to the process.

6. Solaris Papers

Problem The implementation of Solaris threads described in the paper "Beyond Multiprocessing: Multithreading the Sun OS Kernel", describes four key data structures used by the OS to support threads.

For each of these data structures, list at least two elements they must contain: Process LWP Kernel-threads CPU

7. Pipeline Model

Problem An image web server has three stages with average execution times as follows:

Stage 1: read and parse request (10ms) Stage 2: read and process image (30ms) Stage 3: send image (20ms)

You have been asked to build a multi-threaded implementation of this server using the pipeline model. Using a pipeline model, answer the following questions:

How many threads will you allocate to each pipeline stage? What is the expected execution time for 100 requests (in sec)? What is the average throughput of this system (in req/sec)? Assume there are infinite processing resources (CPU's, memory, etc.).

Solution Threads should be allocated as follows: Stage 1 should have 1 thread This 1 thread will parse a new request every 10ms Stage 2 should have 3 threads The requests parsed by Stage 1 get passed to the threads in Stage 2. Each thread picks up a request and needs 30ms to process the image. Hence, we need 3 threads in order to pick up a new request as soon as Stage 1 passes it. Stage 3 should have 2 threads. This is because Stage 2 will process an image and pass a request every 10ms (once the pipeline is filled). In this way, each Stage 3 thread will pick up a request and send an image in 20ms. Once the pipeline is filled, Stage 3 will be able to pick up a request and send the image every 10ms. The first request will take 60ms. The last stage will continue delivering the remaining 99 requests at 10ms intervals. So, the total is 60 + (99 * 10ms) = 1050ms = 1.05s 100 req / 1.05 sec = 95.2 req/s

results matching ""

    No results matching ""