Guarded entries and deadlocks in Ada

  • Thread starter Dafydd
  • Start date
In summary, the conversation discusses a potential deadlock situation in a procedure involving three tasks - Alpha, Bravo, and Charlie. Alpha is guarded by a condition which prevents accepting a call from Bravo, and Bravo has a loop that includes a call to Alpha. The question is whether Bravo will get stuck waiting for Alpha to accept the call, causing a deadlock with Charlie. The person who asked the question has now been able to produce a deadlock and thanks the other person for sharing their logic.
  • #1
Dafydd
12
0
This is a pretty general question that I haven't found an answer to, so I'd really appreciate the help.

Let's say we have 3 tasks - Alpha, Bravo and Charlie, all within the one and same procedure.

Alpha takes calls from Bravo, which in turn takes calls from Charlie.

Alpha's entry is guarded by some condition, which prevents accepting a call from Bravo.

Meanwhile, Bravo has the following loop:

loop
select
accept Call_from_Charlie;
exit;
or
delay 0.0;
Alpha.Do_stuff;
end select;
end loop;

... and all Charlie does is call Bravo.Call_from_Charlie.

Now, my question is: will Bravo ever get stuck waiting for Alpha to accept its call, ignoring Call_from_Charlie until Alpha accepts the Do_stuff call, causing a deadlock with Charlie waiting for Bravo, which is in turn waiting for Alpha?

In other words, when Bravo reaches the line of code reading "Alpha.Do_stuff;", and Alpha won't accept the call because the entry is guarded, what does Bravo do?

I haven't been able to produce a deadlock this way, but I'd like to know whether it's at all possible.

EDIT: I have now been able to produce a deadlock this way. Don't know why it didn't happen the first time, but it does now.
 
Last edited:
Technology news on Phys.org
  • #2
Glad to know that the logic worked out. Additionally, thanks for sharing the logic.
 

FAQ: Guarded entries and deadlocks in Ada

What is a guarded entry in Ada?

A guarded entry in Ada is a synchronization mechanism used to control access to shared resources in a concurrent program. It allows multiple tasks to safely access and modify shared data without causing conflicts or errors.

How does a guarded entry prevent deadlocks?

A guarded entry prevents deadlocks by using a priority-based locking mechanism. This means that when a task attempts to enter a guarded entry, it will only be allowed if it has a higher priority than any other task currently waiting to enter. This ensures that lower priority tasks do not block higher priority tasks, preventing a potential deadlock situation.

What happens if a task cannot enter a guarded entry?

If a task cannot enter a guarded entry, it will be suspended and placed on a waiting queue until the entry becomes available. The task will then resume execution when it is able to enter the guarded entry.

Can a task be suspended while inside a guarded entry?

Yes, a task can be suspended while inside a guarded entry. This is known as a nested suspension. However, the task will still hold the lock on the guarded entry, preventing other tasks from entering until it resumes execution and exits the guarded entry.

Are there any limitations to using guarded entries in Ada?

Yes, there are some limitations to using guarded entries in Ada. For example, a guarded entry cannot be used inside a protected object. Additionally, only one task can enter a guarded entry at a time, so it may not be suitable for certain types of concurrent programs.

Similar threads

Replies
1
Views
2K
Replies
75
Views
5K
Replies
28
Views
5K
Replies
16
Views
2K
Replies
18
Views
5K
Replies
20
Views
3K
6
Replies
175
Views
23K
Back
Top