Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TP Train
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Package registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CELERIER Auguste
TP Train
Commits
fe989744
Commit
fe989744
authored
3 months ago
by
ACHARD Romain
Browse files
Options
Downloads
Patches
Plain Diff
essai
parent
4a2877a3
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/train/Section.java
+8
-8
8 additions, 8 deletions
src/train/Section.java
src/train/Station.java
+2
-2
2 additions, 2 deletions
src/train/Station.java
with
10 additions
and
10 deletions
src/train/Section.java
+
8
−
8
View file @
fe989744
...
...
@@ -8,23 +8,23 @@ package train;
* @author Philippe Tanguy <philippe.tanguy@imt-atlantique.fr>
*/
public
class
Section
extends
Element
{
private
Tra
in
currentTrain
=
null
;
private
in
t
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
}
}
...
...
This diff is collapsed.
Click to expand it.
src/train/Station.java
+
2
−
2
View file @
fe989744
...
...
@@ -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
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment