Home CS439

CS439: Principles of Computer Systems

Discussion Section Problem Set 3

Due in Section on Friday, September 22, 2017

The problem set must be completed before section and brought to section. To ensure that your problem set is turned in correctly and that you receive credit for discussion section, you must follow these guidelines exactly.

  1. When executing system or library calls from multi-threaded code, it is important to know which calls are re-entrant and which are not.
    • What is the meaning of re-entrant?
    • How does a re-entrant call behave differently from a call that is not re-entrant?
    • Why is this an important consideration for multi-threaded code?

  2. What does the function pthread_detach() do? What default behavior of threads does it alter? When might it be useful?

  3. Consider a uniprocessor kernel that user programs can trap into using system calls. The kernel receives and handles interrupts from I/O devices. Would there be any need for critical sections within that kernel?

  4. Describe the priority inversion problem and give an example situation where it may occur.

  5. In the code below, indicate where each variable is stored (e.g., stack, heap, static data segment), and whether that variable would be shared by the threads in a multi-threaded program. If applicable, indicate where the space that variable points to is allocated.

    int i;    
    char * j; 
    
    void foo(int a){
    
       int b;          
       static float c; 
    
       /*do stuff*/
    }
    
    int main(int argc, char**argv){
    
       int * m; 
       int g;   
       double z; 
    
       j = malloc(MAXBUF*sizeof(char));  
    
       createThread(0, foo(), 2);
       createThread(1, foo(), 4);
    
       /*do stuff*/
    }