Menu

Class 14: Homework


You must print this sheet out and write/type answers on it!

  1. Suppose you have a program consisting of two threads: the initial thread, and a new thread corresponding to some function foo. If foo calls the exit function, does the entire process terminate, or just that thread?
    
    
    
    	
  2. Here's the prototype to pthread_create:
    int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void  *(*start_routine)(void*), void * arg);
    	
    Given the following following variable def's and function prototypes, circle the call to pthread_create (given below) that is valid:
    void *foo(void *p);
    int a;
    int *p;
    pthread_t b;
    
     p = pthread_create(b,NULL,foo,a);
    
    *p = pthread_create(b,NULL,foo,a);
    
     p = pthread_create(&b,NULL,foo,a);
    
    *p = pthread_create(&b,NULL,foo,a);
    
     p = pthread_create(b,NULL,foo,&a);
    
    *p = pthread_create(b,NULL,foo,&a);
    
     p = pthread_create(&b,NULL,foo,&a);
    
    *p = pthread_create(&b,NULL,foo,&a);
    
    
    
  3. Suppose A is a process that calls fork, and B is the child process that's created. Circle the resources that are shared between A and B, assuming we're talking about immediately after the fork:

    Suppose A is a thread that calls pthread_create, and B is the thread that's created. Circle the resources that are shared between A and B, assuming we're talking about immediately after the pthread_create call: