"debut TD0"
This commit is contained in:
BIN
2019-2020/S3T_TP_07_THREADS/Demonstrations/demo_mutex
Executable file
BIN
2019-2020/S3T_TP_07_THREADS/Demonstrations/demo_mutex
Executable file
Binary file not shown.
57
2019-2020/S3T_TP_07_THREADS/Demonstrations/demo_mutex.c
Normal file
57
2019-2020/S3T_TP_07_THREADS/Demonstrations/demo_mutex.c
Normal file
@@ -0,0 +1,57 @@
|
||||
///********************************************************************/
|
||||
///* IUT NICE-COTE D'AZUR - Departement INFORMATIQUE - R. CHIGNOLI */
|
||||
///* Module DUT M311 Theme PTHREADS */
|
||||
///********************************************************************/
|
||||
/// demo_mutex.c : Demonstration simple d'utilisation des
|
||||
/// pthreads-mutex rapides.
|
||||
/// Utiliser par exemple les s<>quences LU0 LL0 LULU0 LUUL0
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#include <assert.h>
|
||||
|
||||
pthread_t filsA;
|
||||
pthread_mutex_t fastmutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
char *sequence;
|
||||
|
||||
void* action (void* name) {
|
||||
int encore = 0;
|
||||
while (sequence [encore] != '0') {
|
||||
switch (sequence [encore]) {
|
||||
case 'L': printf("L ... ");
|
||||
if (pthread_mutex_lock (&fastmutex) != 0)
|
||||
printf("... L PB.\n"); else printf("... L OK.\n"); break;
|
||||
case 'U': printf("U ... ");
|
||||
if (pthread_mutex_unlock (&fastmutex) != 0)
|
||||
printf("... U PB.\n"); else printf("... U OK.\n"); break;
|
||||
case 'X': printf("X ... ");
|
||||
if (pthread_mutex_destroy (&fastmutex) != 0)
|
||||
printf("... X PB.\n"); else printf("... X OK.\n"); break;
|
||||
default: printf("... Commande incorrecte\n");
|
||||
}
|
||||
encore ++;
|
||||
}
|
||||
printf("... Bye\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main (int argc, char* argv[]) {
|
||||
pthread_t filsA;
|
||||
assert (argc ==2);
|
||||
sequence = argv[1];
|
||||
printf ("\nEssayer avec les sequences : LU0 LL0 LULU0 LUUL0\n\n");
|
||||
|
||||
if (pthread_create(&filsA, NULL, action, "filsA")) {x
|
||||
perror("pthread_create");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
printf("\nPERE (Thread principal) : boucle infinie\n\n") ;
|
||||
for(;;);
|
||||
return (0);
|
||||
}
|
||||
|
BIN
2019-2020/S3T_TP_07_THREADS/Demonstrations/demo_pthread
Executable file
BIN
2019-2020/S3T_TP_07_THREADS/Demonstrations/demo_pthread
Executable file
Binary file not shown.
38
2019-2020/S3T_TP_07_THREADS/Demonstrations/demo_pthread.c
Normal file
38
2019-2020/S3T_TP_07_THREADS/Demonstrations/demo_pthread.c
Normal file
@@ -0,0 +1,38 @@
|
||||
///********************************************************************/
|
||||
///* IUT NICE-COTE D'AZUR - Departement INFORMATIQUE - R. CHIGNOLI */
|
||||
///* Module DUT M311 Theme PTHREADS */
|
||||
///********************************************************************/
|
||||
/// demo_pthread.c : Demonstration d'utilisation des threads
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
|
||||
void* action (void* name) {
|
||||
printf ("\n... ACTION par thread %s (pid : %d) ... Puis MORT\n\n",
|
||||
(char*) name, getpid());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main (void) {
|
||||
pthread_t filsA, filsB;
|
||||
|
||||
printf ("\nDebut du pere ( pid : %d ; ppid : %d ) )\n\n",
|
||||
getpid(), getppid());
|
||||
|
||||
if (pthread_create(&filsA, NULL, action, "filsA")) {
|
||||
perror("pthread_create");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (pthread_create(&filsB, NULL, action, "filsB")) {
|
||||
perror("pthread_create");
|
||||
exit(-1);
|
||||
}
|
||||
printf("\nFin du pere\n\n") ;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
BIN
2019-2020/S3T_TP_07_THREADS/Demonstrations/demo_system
Executable file
BIN
2019-2020/S3T_TP_07_THREADS/Demonstrations/demo_system
Executable file
Binary file not shown.
22
2019-2020/S3T_TP_07_THREADS/Demonstrations/demo_system.c
Normal file
22
2019-2020/S3T_TP_07_THREADS/Demonstrations/demo_system.c
Normal file
@@ -0,0 +1,22 @@
|
||||
///********************************************************************/
|
||||
///* IUT NICE-COTE D'AZUR - Departement INFORMATIQUE - R. CHIGNOLI */
|
||||
///* Module DUT M311 Theme PTHREADS */
|
||||
///********************************************************************/
|
||||
/// demo_system : Demonstration d'utilisation de "system"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <pthread.h>
|
||||
|
||||
int main (int argc, char* argv[]) {
|
||||
int i;
|
||||
assert (argc == 2);
|
||||
for (i=1; i<=3; i++) { /// 3 : par exemple ...
|
||||
system (argv[1]);
|
||||
printf (" ... Au suivant ...\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
34
2019-2020/S3T_TP_07_THREADS/Demonstrations/ds_pthread.c
Normal file
34
2019-2020/S3T_TP_07_THREADS/Demonstrations/ds_pthread.c
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
|
||||
int GlobV = 0;
|
||||
|
||||
void* action (void* increment) {
|
||||
for (i=1 ; i<= NOMBRE; i++) globV = globV + *increment;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main (int argc; char* argv[]) {
|
||||
pthread_t unThread;
|
||||
int valeur;
|
||||
assert (argc == 2);
|
||||
valeur = atoi(argv[1];
|
||||
|
||||
if (pthread_create(&unThread, NULL, action, &valeur) {
|
||||
perror("pthread_create");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
}
|
||||
printf("\nmain : globV = %d \n\n", globV) ;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
13
2019-2020/S3T_TP_07_THREADS/Demonstrations/makefile
Normal file
13
2019-2020/S3T_TP_07_THREADS/Demonstrations/makefile
Normal file
@@ -0,0 +1,13 @@
|
||||
CFLAGS = -Wall -g -std=gnu99 -lpthread
|
||||
CC = gcc
|
||||
|
||||
EXECUTABLES = demo_pthread \
|
||||
demo_system \
|
||||
pthread10 \
|
||||
demo_mutex
|
||||
|
||||
all : ${EXECUTABLES}
|
||||
|
||||
clean :
|
||||
@rm -f core *.o *.out *~
|
||||
@rm -f ${EXECUTABLES}
|
BIN
2019-2020/S3T_TP_07_THREADS/Demonstrations/pthread10
Executable file
BIN
2019-2020/S3T_TP_07_THREADS/Demonstrations/pthread10
Executable file
Binary file not shown.
38
2019-2020/S3T_TP_07_THREADS/Demonstrations/pthread10.c
Normal file
38
2019-2020/S3T_TP_07_THREADS/Demonstrations/pthread10.c
Normal file
@@ -0,0 +1,38 @@
|
||||
///********************************************************************/
|
||||
///* IUT NICE-COTE D'AZUR - Departement INFORMATIQUE - R. CHIGNOLI */
|
||||
///* Module DUT M311 Theme PTHREADS */
|
||||
///********************************************************************/
|
||||
/// pthread10.c : squelette pour creation de trois threads
|
||||
/// Cf enonce ...
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
typedef struct { int nombre; char car;} struct_p;
|
||||
|
||||
void imprimer (struct_p* param){
|
||||
int i;
|
||||
for (i=0 ; i < param->nombre; i++) printf ("%c", param->car); }
|
||||
|
||||
int main (int argc, char* argv[]) {
|
||||
int i, valeur;
|
||||
struct_p x;
|
||||
char tab[3] = {'/', '*', '='};
|
||||
|
||||
assert (argc == 2);
|
||||
valeur = atoi (argv[1]);
|
||||
for (i=1; i<=3; i++) {
|
||||
printf ("\nMAIN : Tour de boucle nO %d\n", i);
|
||||
/// A VOUS DE JOUER
|
||||
/// Creation des trois threads d'affichage ...
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
BIN
2019-2020/S3T_TP_07_THREADS/Demonstrations/pthread4
Executable file
BIN
2019-2020/S3T_TP_07_THREADS/Demonstrations/pthread4
Executable file
Binary file not shown.
41
2019-2020/S3T_TP_07_THREADS/Demonstrations/pthread4.c
Normal file
41
2019-2020/S3T_TP_07_THREADS/Demonstrations/pthread4.c
Normal file
@@ -0,0 +1,41 @@
|
||||
///********************************************************************/
|
||||
///* IUT NICE-COTE D'AZUR - Departement INFORMATIQUE - R. CHIGNOLI */
|
||||
///* Module DUT M311 Theme PTHREADS */
|
||||
///********************************************************************/
|
||||
/// demo_pthread.c : Demonstration d'utilisation des threads
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
|
||||
void* action (void* name) {
|
||||
printf ("\n... ACTION par thread %s (pid : %d) ... Puis MORT\n\n",
|
||||
(char*) name, getpid());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main (void) {
|
||||
pthread_t filsA, filsB;
|
||||
|
||||
printf ("\nDebut du pere ( pid : %d ; ppid : %d ) )\n\n",
|
||||
getpid(), getppid());
|
||||
|
||||
if (pthread_create(&filsA, NULL, action, "filsA")) {
|
||||
perror("pthread_create");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (pthread_create(&filsB, NULL, action, "filsB")) {
|
||||
perror("pthread_create");
|
||||
exit(-1);
|
||||
}
|
||||
printf("\nFin du pere\n\n") ;
|
||||
|
||||
for(;;) {}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user