|
CSE 410 Computer Systems - Homework 6
- Spring 2009
|
|
Due: Thursday, May 21, at 11 pm.
In this assignment we explore some of the basics of processes and threads.
- (Silberschatz 3.7 [8th ed] / 3.2 [7th ed]) Describe the actions taken by
a kernel to context-switch between processes.
- (Silberschatz 3.13 [8th] / 3.4 [7th], simplified slightly) Given the following
program, explain what output will be produced by line A and why. If there
is more than one possible output depending on the sequence in which different
processes
execute, explain
what the possible outcomes are and how they could happen.
(Although this is a C program,
the details of the language aren't important.
The variable value
is a global variable and the function main
is
the code that makes up the program. A wait(NULL)
function call
causes a process to pause until its child processes exit. A return
inside main
terminates
the current process. The printf
function prints the string "value
=" followed
by the contents of variable value
.)
int value = 5;
int main {
pid = fork();
if (pid == 0) {
value = value + 15;
return 0;
} else {
wait(NULL); /* wait for child process to terminate */
printf("value = %d", value); /* LINE A */
return 0;
}
- (Silberschatz 4.1 [8th]) Provide two programming examples in which multithreading
provides better performance than a single-threaded solution. (In this and
the next question, you don't need to write out detailed code; pseudo-code
or a sketch is fine, but be reasonably specific.)
- (Silbershatz 4.7 [8th] / 4.1 [7th]) Provide two programming examples in
which multithreading does not provide better performance than a
single-threaded solution.
- (Silberschatz 4.8 [8th] / 4.2 [7th]) Describe the actions taken by a thread
library to context switch between user-level threads.
- (Silberschatz 4.10 [8th] / 4.4 [7th]) Which of the following components
of program state are shared across threads in a multithreaded process?
- Register values
- Heap memory
- Global variables
- Stack memory
Turn-in Instructions:
Use the turn-in drop box link on the main course web page to submit a file containing
your solutions. You can use any common file format, including plain text, word,
or pdf. If you wish, you could also scan in a hand-written solution and submit
that, but if you do that, please be sure your handwriting is neat and
legible. Please be sure to include your name at the top of your answers.
|
![CSE logo](/images/logo.png) |
Computer Science & Engineering
University of Washington
Box 352350
Seattle, WA 98195-2350
(206) 543-1695 voice, (206) 543-2969 FAX
[comments to Hal Perkins]
|