Nantes Université
Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
I
infem-tp-bac
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de conteneurs
Registre de modèles
Opération
Environnements
Surveillance
Incidents
Service d'assistance
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Mikaël BRIDAY
infem-tp-bac
Validations
f1cd0835
Valider
f1cd0835
rédigé
4 years ago
par
Mikaël BRIDAY
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
ajout ou2semaphore, avec ou sans timeout.
parent
4e588144
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
3
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
3 fichiers modifiés
.gitignore
+2
-0
2 ajouts, 0 suppression
.gitignore
sys/infem.py
+43
-30
43 ajouts, 30 suppressions
sys/infem.py
sys/infemGUI.py
+8
-0
8 ajouts, 0 suppression
sys/infemGUI.py
avec
53 ajouts
et
30 suppressions
.gitignore
+
2
−
0
Voir le fichier @
f1cd0835
*~
## Corrections..
tpBacQ*.py
## Vim...
.*.swp
##python
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
sys/infem.py
+
43
−
30
Voir le fichier @
f1cd0835
...
...
@@ -21,15 +21,14 @@ class Semaphore():
if the value is > 0, it decrements the semaphore value and returns
otherwise, it blocks until value get > 0
"""
__synchro__
.
acquire
()
#get the lock
while
self
.
value
<=
0
:
with
__synchro__
:
while
self
.
value
<=
0
:
if
sModel
:
sModel
.
addWaitingThread
(
self
,
threading
.
currentThread
().
name
)
__synchro__
.
wait
()
self
.
value
-=
1
if
sModel
:
sModel
.
addWaitingThread
(
self
,
threading
.
currentThread
().
name
)
__synchro__
.
wait
()
self
.
value
-=
1
if
sModel
:
sModel
.
update
(
self
)
__synchro__
.
release
()
sModel
.
update
(
self
)
def
P
(
self
):
"""
same as
'
acquire
'
. wrapper for historical reasons
"""
...
...
@@ -39,44 +38,58 @@ class Semaphore():
"""
release the semaphore.
the value is incremented and a waiting threads can be woken up. Non blocking call.
"""
__synchro__
.
acquire
()
#get the lock
#notify all so that they are blocked again and we can deduce
#the list of waiting threads.
__synchro__
.
notify_all
()
self
.
value
+=
1
if
sModel
:
sModel
.
clearWaitingThread
(
self
)
__synchro__
.
release
()
with
__synchro__
:
#notify all so that they are blocked again and we can deduce
#the list of waiting threads.
__synchro__
.
notify_all
()
self
.
value
+=
1
if
sModel
:
sModel
.
clearWaitingThread
(
self
)
def
V
(
self
):
"""
same as
'
release
'
. wrapper for historical reasons
"""
self
.
release
()
def
ou2Semaphore
(
s1
,
s2
):
def
ou2Semaphore
(
s1
,
s2
,
timeout
=
None
):
"""
Wait for the first available semaphore between 2. If the 2 are available, s1 is chosen.
returns 1 if s1 is chosen, 2 if s2. This is a blocking call.
"""
if
not
isinstance
(
s1
,
Semaphore
)
or
not
isinstance
(
s2
,
Semaphore
):
raise
Exception
(
'
Input is not a semaphore in ou2Semaphore
'
)
result
=
0
__synchro__
.
acquire
()
#one already available
if
s1
.
value
>
0
:
result
=
1
s1
.
value
-=
1
elif
s2
.
value
>
0
:
result
=
2
s2
.
value
-=
1
while
result
==
0
:
# we will block
__synchro__
.
wait
()
with
__synchro__
:
#one already available
if
s1
.
value
>
0
:
result
=
1
s1
.
value
-=
1
if
sModel
:
sModel
.
update
(
s1
)
elif
s2
.
value
>
0
:
result
=
2
s2
.
value
-=
1
__synchro__
.
release
()
if
sModel
:
sModel
.
update
(
s2
)
while
result
==
0
:
# we will block
if
sModel
:
threadName
=
threading
.
currentThread
().
name
sModel
.
addWaitingThread
(
s1
,
threadName
)
sModel
.
addWaitingThread
(
s2
,
threadName
)
noTimeout
=
__synchro__
.
wait
(
timeout
)
if
noTimeout
:
if
s1
.
value
>
0
:
result
=
1
s1
.
value
-=
1
if
sModel
:
sModel
.
update
(
s1
)
sModel
.
removeWaitingThread
(
s2
,
threading
.
currentThread
().
name
)
elif
s2
.
value
>
0
:
result
=
2
s2
.
value
-=
1
if
sModel
:
sModel
.
removeWaitingThread
(
s1
,
threading
.
currentThread
().
name
)
sModel
.
update
(
s2
)
else
:
#timeout
result
=
3
#timeout
return
result
Ce diff est replié.
Cliquez pour l'agrandir.
sys/infemGUI.py
+
8
−
0
Voir le fichier @
f1cd0835
...
...
@@ -55,6 +55,14 @@ class SemaphoreModel(QAbstractTableModel):
self
.
semaphores
[
idx
]
=
(
sem
.
name
,
sem
.
value
,
self
.
semaphores
[
idx
][
2
])
self
.
dataChanged
.
emit
(
self
.
index
(
idx
,
0
),
self
.
index
(
idx
,
2
))
def
removeWaitingThread
(
self
,
sem
,
threadName
):
with
self
.
mutex
:
idx
=
self
.
semaphoreNames
[
sem
.
name
]
self
.
waitingThreads
[
sem
.
name
].
remove
(
threadName
)
threads
=
'
-
'
.
join
(
self
.
waitingThreads
[
sem
.
name
])
self
.
semaphores
[
idx
]
=
(
sem
.
name
,
-
len
(
self
.
waitingThreads
[
sem
.
name
]),
threads
)
self
.
dataChanged
.
emit
(
self
.
index
(
idx
,
0
),
self
.
index
(
idx
,
2
))
def
addWaitingThread
(
self
,
sem
,
threadName
):
with
self
.
mutex
:
idx
=
self
.
semaphoreNames
[
sem
.
name
]
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter