Skip to content
Snippets Groups Projects
Commit fe989744 authored by ACHARD Romain's avatar ACHARD Romain
Browse files

essai

parent 4a2877a3
No related branches found
No related tags found
No related merge requests found
......@@ -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
}
}
......
......@@ -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
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment