HW4 released: 02/09, 20:00 due: 02/15, 23:59 Answer the following questions. Submit your answers to Canvas assignments. There is an entry for this homework. 1. Processes vs. Threads (3 points) One process can have multiple threads running at the same time. If one of the threads calls fork(), what will the child process look like? Will the child process: - (a) has all threads? - or (b) only has the thread call fork()? - or (c) only has the thread running main() function? - or (d) something else? If you were an OS developer, which above options will you choose? (1 point) And why? Explain why you like the option in a few sentences. (2 points) [note: this is an open question.] 2. pthread and compiler (7 points) Below is an example we talked about in class. #include "unistd.h" #include "stdio.h" #include "pthread.h" int x = 0; // a global variable void *foo(void *ptr) { for (int i=0; i<100; i++) { x = 1; printf("%d", x); } return NULL; // do nothing } void *bar(void *ptr) { x = 0; return NULL; // do nothing } int main(){ // TODO: your code here } 2.a (3 points) You are supposed to finish the main function and create two threads: one runs function "foo"; the other runs "bar". The main thread should wait the two threads to finish. Please write down your code below: [hints: - you will use pthread - the reading introduces how to use pthread: https://pages.cs.wisc.edu/~remzi/OSTEP/threads-api.pdf ] 2.b (2 points) Compile your code using "gcc -O3" and run your code 10 times. Did you see any "0" in the output? If yes, copy paste your outputs below. If no, say "NO". 2.c (2 points) Compile your code using "gcc -O0". Repeat what you've done for question 2.b and answer the same question below. 2.d (0 points) If you see multiple "0"s in any of your outputs, please write down "COMPILER DID THIS!" below. Otherwise, ignore this question.