Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
G17_bykes_prog_concurrente
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
remi.greub
G17_bykes_prog_concurrente
Commits
8a80a147
Commit
8a80a147
authored
1 month ago
by
remi.greub
Browse files
Options
Downloads
Patches
Plain Diff
affichage terminé
parent
56210a76
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
G17_bykes/main.c
+16
-11
16 additions, 11 deletions
G17_bykes/main.c
with
16 additions
and
11 deletions
G17_bykes/main.c
+
16
−
11
View file @
8a80a147
...
...
@@ -19,6 +19,7 @@ pthread_mutex_t *mutex;
pthread_barrier_t
b
;
bool
end
=
false
;
int
personsFinished
=
0
;
struct
habitant
{
int
num_thread
;
...
...
@@ -35,6 +36,7 @@ struct camionette{
int
i_site
;
int
nbSites
;
int
nbornes
;
int
nbHabs
;
};
struct
site
{
...
...
@@ -59,6 +61,7 @@ int main(int argc, char **argv){
int
nbHabs
=
atoi
(
argv
[
2
]);
//H 100
int
nbTrajets
=
atoi
(
argv
[
3
]);
//M 10
int
nbBorne
=
atoi
(
argv
[
4
]);
//N 10
nbSites
+=
1
;
srand
(
0
);
...
...
@@ -72,14 +75,14 @@ int main(int argc, char **argv){
sites
[
j
].
nb_bikesParked
=
nbBorne
-
2
;
sites
[
j
].
nb_P_waiting
=
0
;
}
sites
[
0
].
nb_bikesParked
=
0
;
//depot avec 0 velos au depart
sites
[
DEPOT
].
nb_bikesParked
=
0
;
//depot avec 0 velos au depart
camion
->
i_site
=
0
;
camion
->
n_Velo
=
CAMION_CAPACITE_TYP
;
camion
->
nbornes
=
nbBorne
;
camion
->
num_thread
=
nbHabs
;
camion
->
nbSites
=
nbSites
;
camion
->
nbHabs
=
nbHabs
;
sem_BikeFree
=
malloc
(
sizeof
(
sem_t
)
*
nbSites
);
sem_BorneFree
=
malloc
(
sizeof
(
sem_t
)
*
nbSites
);
...
...
@@ -139,11 +142,13 @@ int main(int argc, char **argv){
free
(
sem_BikeFree
);
free
(
sem_BorneFree
);
free
(
mutex
);
printf
(
"***************** CYCLING TERMINATED ***************
\n
"
);
int
sum
=
0
;
for
(
int
i
=
0
;
i
<
nbSites
;
i
++
){
for
(
int
i
=
1
;
i
<
nbSites
;
i
++
){
printf
(
"Terminal %d contains %d bikes
\n
"
,
i
,
sites
[
i
].
nb_bikesParked
);
sum
+=
sites
[
i
].
nb_bikesParked
;
}
printf
(
"
nb de velos en fin de programme %d
\n
"
,
sum
);
printf
(
"
total number of bikes in town: %d, in depot: %d, in truck: %d, total: %d
\n
"
,
sum
,
sites
[
DEPOT
].
nb_bikesParked
,
camion
->
n_Velo
,
camion
->
n_Velo
+
sites
[
DEPOT
].
nb_bikesParked
+
sum
);
free
(
habs
);
free
(
camion
);
...
...
@@ -233,14 +238,13 @@ void *habitants(void *arg){
hab
->
i_site
=
j
;
hab
->
nb_trajet
+=
1
;
}
//printf("machin bidule finished : %d, tot_trajets = %d\n", hab->num_thread, hab->nb_trajet);
printf
(
"person %d stops
\n
"
,
hab
->
num_thread
);
pthread_mutex_lock
(
&
mutex
[
hab
->
i_site
]);
personsFinished
+=
1
;
pthread_mutex_unlock
(
&
mutex
[
hab
->
i_site
]);
pthread_barrier_wait
(
&
b
);
//printf("machin bidule a passé la barriere !!!! : %d, tot_trajets = %d\n", hab->num_thread, hab->nb_trajet);
pthread_mutex_lock
(
&
mutex
[
hab
->
i_site
]);
end
=
true
;
pthread_mutex_unlock
(
&
mutex
[
hab
->
i_site
]);
return
NULL
;
}
...
...
@@ -248,7 +252,7 @@ void *Camion(void *arg){
struct
camionette
*
camion
=
(
struct
camionette
*
)
arg
;
int
tmp_nbBikes
;
while
(
!
end
){
while
(
personsFinished
<
camion
->
nbHabs
){
//1 : for each sites from 1 to S (0 is the depot)
for
(
int
i
=
1
;
i
<
camion
->
nbSites
;
i
++
){
//spreads the bikes evenly
...
...
@@ -314,8 +318,9 @@ void *Camion(void *arg){
}
//3: pause betweem 100us up to 199us
usleep
(
rand_Dc
());
printf
(
"TRUCK new loop, person's threads finished: %d
\n
"
,
personsFinished
);
}
printf
(
"
end camion
\n
"
);
printf
(
"
TRUCK end loop
\n
"
);
return
NULL
;
}
...
...
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