1. Describe the difference between a process and a thread (2 points). 2. Which o
ID: 3805657 • Letter: 1
Question
1. Describe the difference between a process and a thread (2 points).
2. Which of the following components of program are shared across threads in a multithreaded process Select all that apply. (1 points)?
a. Register valuesb. Heap memoryc. Global variablesd. Stack memory
3. What is a busy waiting? What is an alternative to busy waiting ?(2 points)
4. What is the distinction between the critical section and the critical data?(2 points)5. Describe the difference between a monitor and a semaphore (2 points).
COP4610 HW2 2
6. A file is to be shared among different processes, each of which has a unique id number and a priority levelnumber. The file can be accessed simultaneously by several processes, subject to the following constraint:The process priority number must be greater than or equal to the priority numbers all of the other processesthat are currently accessing the file. Using pseudocode (see below), write a monitor to coordinate access to the file. (6 points)
7. There are three cooperating processes. They all read data from the same input device. Each process, when itgets the input device, must read two consecutive data, only one process may access the input device at a time(Hint: use mutual exclusion to achieve it). Use semaphores to synchronize. Include declaration and initialization.(SEE example on BB – and Video on ) (8 points)
P1: input (x1, x2) P2: input (y1, y2) P3: input (z1, z2)C = y1 + z1 B = x1 + z2 + A A = y2 –x2 ` Print D D = B + C
8. Consider the following snapshot of a system(6 points)R1 has 8 instances, R2 has 10 instances, and R3 has 7 instances
Allocation Max Need Available
Is the system in a safe state? If yes, list an ordered sequence of processes. Show all work.
Explanation / Answer
Ans 1) The differences between thread and process are:-
> A program in execution is called process. Thread is subpart of process
> Thread share the address space of the process which created it and process have their own address space
> A process consists of multiple threads. A thread is a smallest part of the process that can execute concurrently with other parts(threads) of the process
> Threads have direct access to the data segment of its process; processes have their own copy of the data segment of the parent process
> A process is sometime referred as task. A thread is often referred as lightweight process.
> Threads can exercise considerable control over threads of the same process; processes can only exercise control over child processes
Ans 2)
a) Register value can be shared by mulithreading. But in case of regsister the CPU decides to switch from one thread to another, the OS saves the current values of all the register into a private memory area specific to the first thread. Before the second thread starts running, the OS loads the values of all the registers from its saved area. This is called a context switch.
b) Heap are used by multithreads
c) Global variables are shared
d) Each threads have their own private stack
Ans 3) Busy waiting is a technique in which a process repeatdely checks to see if a condition is true.
Ans 4) A critical section is piece of code that accesses a shared resource that must not be concurrently accessed by more than one thread of execution.
Ans 5) Monitor is like a bathroom if one person goes inside he locks it and other person to use it he has to wait till the person comes out of bathroom. Semaphore is like public cab service , there are limited mo of cabs if the cab is free then the person can use it.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.