From fe989744ce9df59da616d27f0441c7bbf503365f Mon Sep 17 00:00:00 2001 From: romain achard <romain.achard@imt-atlantique.net> Date: Mon, 3 Feb 2025 16:41:11 +0100 Subject: [PATCH] essai --- src/train/Section.java | 16 ++++++++-------- src/train/Station.java | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/train/Section.java b/src/train/Section.java index 25d2f03..7e77a97 100644 --- a/src/train/Section.java +++ b/src/train/Section.java @@ -8,23 +8,23 @@ package train; * @author Philippe Tanguy <philippe.tanguy@imt-atlantique.fr> */ public class Section extends Element { - private Train currentTrain = null; + private int currentTrain = 0; public Section(String name) { super(name); - this.currentTrain = null; + this.currentTrain = 0; } - public synchronized void enterSection(Train t) throws InterruptedException { - while (currentTrain != null) { // Attendre que la section soit libre + public synchronized void enterSection() throws InterruptedException { + while (currentTrain != 0) { // Attendre que la section soit libre wait(); } - currentTrain = t; + currentTrain = 1; } - public synchronized void leaveSection(Train t) { - if (currentTrain == t) { - currentTrain = null; + public synchronized void leaveSection() { + if (currentTrain == 1) { + currentTrain = 0; notifyAll(); // Réveille les trains en attente } } diff --git a/src/train/Station.java b/src/train/Station.java index 53eeb4a..627baaa 100644 --- a/src/train/Station.java +++ b/src/train/Station.java @@ -20,14 +20,14 @@ public class Station extends Element { this.currentTrain = 0; } - public synchronized void enterStation(Train t) throws InterruptedException { + public synchronized void enterStation() throws InterruptedException { while (currentTrain >= size) { // Si la gare est pleine, attendre wait(); } currentTrain++; } - public synchronized void leaveStation(Train t) { + public synchronized void leaveStation() { currentTrain--; notifyAll(); // Réveille les trains en attente } -- GitLab