

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Quiz; Professor: Syrotiuk; Class: Operating Systems; Subject: Computer Science and Engineering; University: Arizona State University - Tempe; Term: Fall 2012;
Typology: Quizzes
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Instructor: Dr. Violet R. Syrotiuk
Available Tuesday 08/28/2012; due Tuesday 09/11/
This assignment covers Chapter 3 “Process Description and Control,” Chapter 4 “Threads,” and part of Chapter 5 “Concurrency: Mutual Exclusion and Synchronization.”
(a) Find the equivalent of the process state transition diagram and process control block (PCB) and discuss how they compare to the seven-state process state transition diagram (Figure 3.9) and PCB (Table 3.5). Give sources for your information. [15 marks] (b) If your OS is multi-threaded, which elements of the PCB should belong to a thread control block and which should belong to a PCB? [5 marks]
int global_positives = 0;
typedef struct list{ struct list next; double value; } list;
void count_positives( list ell ){ list p; for( p = ell; p; p = p->next ) if( p->value > 0.0 ) ++global_positives; }
Consider the case in which thread A performs count positives on a list containing only negative values while thread B performs ++global positives;.
(a) What does the function do? (b) The C language only addresses single-threaded execution. Does the use of two concurrent threads create any problems or potential problems? (c) Some optimizing compilers (including gcc, which tends to be relatively conservative) will “opti- mize” count positives to something similar to: void count_positives( list ell ){ list p; register int r; r = global_positives; for( p = ell; p; p = p->next ) if( p->value > 0.0 ) ++r; global_positives = r; } What problem or potential problem occurs with this compiled version of the program if threads A and B are executed concurrently?
int x;
void f(){ void main(){ while( 1 ){ x = 10; x = x - 1; parbegin( f, f ); x = x + 1; } if( x != 10 ) printf( "x is %d\n", x ); } }
(a) Show a sequence (i.e., trace the sequence of interleavings of statements) such that the statement x is 10 is printed. [5 marks] (b) Show a sequence such that the statement x is 8 is printed. [5 marks] Remember that the increment/decrement at the source language level may not be atomic. For example, 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.