"depot M311"

This commit is contained in:
JunkJumper
2020-05-02 00:01:03 +02:00
parent f0c24b24e0
commit 16e128821d
83 changed files with 0 additions and 2045 deletions

View File

@@ -1,57 +0,0 @@
///********************************************************************/
///* 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);
}

View File

@@ -1,38 +0,0 @@
///********************************************************************/
///* 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);
}

View File

@@ -1,22 +0,0 @@
///********************************************************************/
///* 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;
}

View File

@@ -1,34 +0,0 @@
//
#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);
}

View File

@@ -1,13 +0,0 @@
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}

View File

@@ -1,38 +0,0 @@
///********************************************************************/
///* 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;
}

View File

@@ -1,41 +0,0 @@
///********************************************************************/
///* 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);
}