[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlaplus] Modelling the Philosophers Dining Problem



Hello,

sorry for the late reply.

Did you use TLC to check your spec? It tells you that it is deadlocked in the initial state. The reason is the definition

ChangeStatus(p) == /\ LET status == IF Cardinality(PhiloStatus[p].forks) = 2 THEN "Eating" ELSE "Thinking"
                        IN /\ PhiloStatus' = [ PhiloStatus EXCEPT ![p].status = status ]

PickForkP(f,p) == /\ \A ph \in Philosophers : f \notin PhiloStatus[ph].forks \* fork f isn't used by anyone
                  /\ PhiloStatus[p].status = "Thinking"
                  /\ PhiloStatus' = [ PhiloStatus EXCEPT ![p].forks = @ \cup {f} ]
                  /\ ChangeStatus(p)

Here you are trying to do two updates to PhiloStatus, this is not going to work.

Some minor remarks:
- Why do you declare Philosophers, Forks, and Statuses as constant parameters when they can be defined?
- Why even record the thinking or eating status of a philosopher in the state: we can just assume that a philosopher is "eating" if she holds two forks and "thinking" otherwise (or if you prefer, "thinking" is she holds no fork and "waiting" if she hold one fork)?

I simplified your spec based on these ideas, see the attached module. Now TLC gives me the following results (for Max=5):

- when disabling deadlock checking and verifying type correctness, it generates 243 distinct states (so the state space is not trivial anymore),
- when verifying the predicate NeverEat, it produces a counter-example showing that philosophers are indeed able to eat,
- however, when checking for deadlocks, it shows the deadlock state where each philosopher holds one fork and cannot acquire the second one.

Now you'll have to find a way to avoid this deadlock state. Only then worry about verifying liveness properties.

Stephan

--
You received this message because you are subscribed to the Google Groups "tlaplus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tlaplus+unsubscribe@xxxxxxxxxxxxxxxx.
To view this discussion on the web visit https://groups.google.com/d/msgid/tlaplus/963685A6-8C00-4DE5-B643-68B36067BD64%40gmail.com.

Attachment: Dining.tla
Description: Binary data



On 14 Feb 2021, at 13:35, Younes <younesagma@xxxxxxxxx> wrote:

Thank you, Stephan, for your remarks.

I have made a few changes in the design (still in progress). I now consider that there are many actions that a philosopher can do : Eating, Taking/Putting the right/left fork, or Doing Nothing. All actions except "Eating" are part of the "Thinking" state. What do you think ?

I know that a philosopher should alternate between eating and thinking, but I think some 'intermediate' states are required to design the problem (especially if a philosopher can either pick or put one fork, but not both at the same).

I have written the "PickFork" action, but not the "PutFork" action yet. What do you think of what I have done so far ? Do you think this design / perspective is "correct" ?

Thank you again,

On Wednesday, February 10, 2021 at 3:48:19 PM UTC+1 Stephan Merz wrote:
Hello,

two quick remarks.

1. The definition of your next-state relation is

Next == \A p \in Range(Philosophers) : (StartEating(p) /\ StopEating(p)) \/ StartThinking(p)
This is saying that *all* philosophers move at every system transition. You certainly want to specify that *some* philosopher takes a move, so replace \A with \E.

Also, the body of that formula asserts that either a philosopher starts thinking or that she starts and stops eating simultaneously. Again, this is certainly wrong. One could imagine that thinking and eating alternate, so "start thinking" doesn't need to be a separate transition (because a philosopher starts thinking as soon as she stops eating), but starting and stopping eating should not occur simultaneously.

2. The real challenge in the problem is to avoid the deadlock situation that occurs when each philosopher holds one fork but cannot acquire the second one because it is held by her neighbor. You trivialized that problem by having each philosopher take up and lay down both forks simultaneously. The original formulation of the problem states that forks are taken up individually (see also [1]). This is what makes the problem interesting.

Stephan

On 10 Feb 2021, at 14:32, Younes <youne...@xxxxxxxxx> wrote:

Hi everyone,

I'm new to TLA+ and I'm trying to model the Philosophers Dining Problem.

My initial setup puts all philosophers into "thinking" and all forks to be "available".

I have a deadlock in my current model, and I think, it is because :
The Next action describes : the alternation (\/) of Thinking and Eating actions. This state of the system (all philosophers are thinking) can occur indefinitely.

How do I combine alternation of the actions (think & eat) in the system whilst avoiding a deadlock ? An intermediate state ? I'm confused.

Also, I will be grateful to take any remarks/comments about the design, or the approach. I am really looking forward into getting your critics / reviews.

TLA+ Source Code :

Thank you all

-- 
You received this message because you are subscribed to the Google Groups "tlaplus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tlaplus+u...@xxxxxxxxxxxxxxxx.
To view this discussion on the web visit https://groups.google.com/d/msgid/tlaplus/979b04c6-736f-4722-b986-72edea346f7bn%40googlegroups.com.


-- 
You received this message because you are subscribed to the Google Groups "tlaplus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tlaplus+unsubscribe@xxxxxxxxxxxxxxxx.
To view this discussion on the web visit https://groups.google.com/d/msgid/tlaplus/5c61177a-49c9-4a1a-a25e-74945d9e9809n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "tlaplus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tlaplus+unsubscribe@xxxxxxxxxxxxxxxx.
To view this discussion on the web visit https://groups.google.com/d/msgid/tlaplus/963685A6-8C00-4DE5-B643-68B36067BD64%40gmail.com.