Reference no: EM133136850
Question: Write a program in C language, called simulator.c that does the following.
a) The parent thread creates six child threads, i.e., thread A, B, C, D, E, and F that respectively runs the FCFS, SSTF program, SCAN, C-SCAN, LOOK, and C-LOOK disk schedulers. Threads A, B, C, D, E, and F block while waiting for input from the parent thread.
b) The parent thread waits for an input from the user. The input can be either a file name, e.g., input!, or "QUIT". When the parent thread receives "QUIT" as input, it tells threads A, B, C, D, E, and F to terminate, and terminates itself. Each child thread should print the following message (Thread_ID is the ID of the thread):
Thread ID has terminated
c) For each file name, e.g., input 1 , the program does the following:
The parent thread stores the contents of the input, e.g., input 1 , in a buffer, called bufferl, and signals thread A, B, C, D, E, and F to read buffer!. The parent thread then blocks while waiting for results from threads A, B, C, D, E, and F, i.e., the seek time. Notice that the parent thread acts as a producer and threads A, B, C, D, E, and F as the consumers for buffer! of size n+3; bufferl stores only the content of input file that has n disk requests and three other information; see the format of input. The simulator must solve any possible synchronization/critical section issues among the threads. You must describe the possible issues and how you solve the issues. Use pthread_createO, pthread_mutex_lockO, pthread_mutex_unlockO, pthread_cond_waito, and pthread_cond_signalO in your program.
Each child thread that has computed the seek time writes the result in another buffer, called buffer2, and signals the parent thread to read the result. Then the child thread blocks waiting for another input from the parent thread. For this case, the parent thread acts as a consumer and threads A, B, C, D, E, and F as the producers for a bounded buffer of size 1, i.e., buffer2 can store only one seek time at a time. The simulator must solve any possible synchronization/critical section issues among the threads. You must describe the possible issues and how you solve the issues. Use pthread_createO, pthread_mutex_lock(), pthread_mutex_unlock(), pthread_cond_waitO, and pthread_cond_signalO in your program.
After the parent thread receives the results from the six threads, it should print the results, e.g.,
For input1:
FCFS: 640.
SSTF: 236.
SCAN: 236.
C-SCAN: 386.
LOOK: 222.
C-LOOK: 326.
You MAY make your own assumptions/requirements other than those already given. However, YOU HAVE TO DOCUMENT ANY ADDITIONAL ASSUMPTIONS/LIMITATIONS FOR YOUR IMPLEMENTATIONS.