
CSCE 351 Operating System Kernels
Fall 2001
Steve Goddard
Homework 1, September 25
Due: 12:30pm October 4
____________________________________________________________
1) (10 points) Consider the following program:
P1: { P2:{
shared int x; shared int x;
x = 10; x = 10;
while (1) { while ( 1 ) {
x = x - 1; x = x - 1;
x = x + 1; x = x + 1;
if (x != 10) if (x!=10)
printf(‘‘x is %d’’,x); printf(‘‘x is %d’’,x);
} }
} }
} }
Note that the scheduler in a uni-processor system would implement pseudo-parallel execution of
these two concurrent processes by interleaving their instructions, without restriction on the order
of the interleaving.
a) Show how (i.e., trace the sequence of inter-leavings of statements) such that the
statement ‘‘x is 10’’ is printed.
b) Show how the statement ‘‘x is 8’’ is printed. You should remember that the
increment/decrements at the source language level are not done atomically, i.e., the
assembly language code:
LD R0,X /* load R0 from memory location x */
INCR R0 /* increment R0 */
STO R0,X /* store the incremented value back in X */
implements the single C increment instruction (x=x+1).
2) (5 points) In view of the fact that existence of a super-user (as the user with administration
privileges is often called in UNIX) can lead to all kinds of security problems, why does such
a concept exist?
What are the pros and cons of having a super-user account?
3) (5 points) In a system with threads, is there one stack per thread or one stack per process?
Explain.
4) (10 points) Why is the process table needed in a timesharing system?