Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The pseudocode of Figure 6.15 illustrates the basic push() and pop() operations of the based stack
array. Assuming that this algorithm can be used in a concurrent execution environment, return
answer the following questions:
a. Which data has competitive status?
b. How can the competitive situation be corrected?


What I have tried:

push(item){
    if (top < SIZE){
        stack[top] = item;
        top++;
    }
    else
        ERROR
}

pop(){
    if (!isempty()){
        top--;
        return stack[top];
    }
    else
        ERROR
}

isempty(){
    if (top == 0)
        return true;
    else
        return false;
}
Posted
Updated 4-Aug-21 2:08am
Comments
CHill60 4-Aug-21 6:27am    
Do you have a specific question or are you just asking us to do your homework assignment for you?
Nguyễn Tiến Phát 4-Aug-21 9:35am    
No. I just want the way to approach the problem

1 solution

To answer part (a), look at each function and think about what would happen if software on CPU1 calls the function and software on CPU2 also calls the same function (or even another of the stack functions), so that both processors are using the stack at the same time.

Even on a single-processor system, a similar thing happens if one thread calls a stack function, is preempted somewhere in the middle of that function, and the next thread also calls a stack function.

Once you've found ways that concurrent calls to push() and pop() could corrupt the stack, or isempty() could return the wrong result, you can answer part (b) by choosing a technique that eliminates race conditions. Here, minimizing overhead is the goal, and the techniques chosen could be different on a single-processor system and a multiprocessor system.
 
Share this answer
 
v2
Comments
Nguyễn Tiến Phát 4-Aug-21 9:34am    
Can you suggest me a technique to remove race conditions ?
Greg Utas 4-Aug-21 10:12am    
If this is an assignment, you should already be familiar with them. Some of them are semaphores, mutexes, atomic operations, and spinlocks.
Nguyễn Tiến Phát 4-Aug-21 21:48pm    
Thanks
Greg Utas 5-Aug-21 18:41pm    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900