Pt1420 Case 3.1

Words: 1561
Pages: 7

(3.1)
Ans: The Output at Line A is “PARENT: value = 5”. When the child process is called by the Parent process , the child process creates its own duplicate copy of the variable “value” and changes its value. So the original variable “value” will be the same. Hence at the Line A , the value will be 5. (3.8) Ans: Short-term:
• It is used to select a process from the jobs that are ready to execute in memory and allocates CPU to that process.
• It will select a new process every time. Medium-term:
• It is a memory manager that selects from ready queue or from the blocked queue and it removes from memory.
• After removing from memory it reinstates them to continue running later. Long-term:
• It is used to
…show more content…
Here we can notify the inconsistency which is not to be done.
 To clear this race condition problem we must apply Peterson’s Algorithm: int turn=0 boolean flag[2];
• “Turn” shows that which user to access the account for the next.
• “flags” makes the events of two users to access the software mutually clear.
This is how to prevent the race condition without any problem.

(5.15) Ans: using test_and_set() typedef struct
{
int available; lock; void init(lock *mutex) {
/* 0 indicates lock is available and 1 indicates it is held */ mutex->available=0; } void acquire(lock *mutex) { while(test_and_set(&mutex->available,1)==1){mutex->available=1;}
}
void release(lock *mutex)
{
mutex->available=0;
}
Using Compare_and_swap(): typedef struct
{
int available; }lock; void init(lock *mutex)
{
/* 0 indicates lock is available and 1 indicates it is held */ mutex->available=0; } void acquire(lock *mutex)
{
while(compare_and_swap(&mutex->available,0,1)==1){//spin wait(do nothing)}
}
void release(lock *mutex)
{