Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
if (fork() == 0) {
signal(SIGINT, sigintF);
while (1) {
if (fork() == 0) {
signal(SIGINT, sigintF);
while (1) {
sleep(1);
}
}
while (1) {
signal(SIGINT, sigintP);
sleep(1);
}
}
while (1) {
signal(SIGINT, sigintP);
#define val 1
sem_t mutex; // sémaphore
#define val 1
sem_t mutex; // sémaphore
+static int var_glob = 0;
void *increment(void *);
void *decrement(void *);
void *increment(void *);
void *decrement(void *);
// attendre la fin des threads
pthread_join(threadA, NULL);
pthread_join(threadB, NULL);
// attendre la fin des threads
pthread_join(threadA, NULL);
pthread_join(threadB, NULL);
- printf("ici main, fin threads : var_glob =%d \n", var_glob);
+ printf("ici main, fin threads : var_glob = %d\n", var_glob);
var_glob = var_glob - 1;
printf("ici sc de decrement: var_glob= %d\n", var_glob);
sem_post(&mutex);
var_glob = var_glob - 1;
printf("ici sc de decrement: var_glob= %d\n", var_glob);
sem_post(&mutex);
}
void *increment(void *nothing)
}
void *increment(void *nothing)
var_glob = var_glob + 1;
printf("ici sc de increment: var_glob= %d\n", var_glob);
sem_post(&mutex);
var_glob = var_glob + 1;
printf("ici sc de increment: var_glob= %d\n", var_glob);
sem_post(&mutex);
#include <stdlib.h>
#include <unistd.h>
#include <stdlib.h>
#include <unistd.h>
static void action(int sig)
{
static void action(int sig)
{
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
-void afficher(int n, char lettre)
+static void afficher(int n, char lettre)
{
int j;
for (j = 1; j < n; j++) {
{
int j;
for (j = 1; j < n; j++) {
-void *threadA(void *inutilise)
+static void *threadA(void *inutilise)
{
afficher(100, 'A');
printf("\n Fin du thread A\n");
{
afficher(100, 'A');
printf("\n Fin du thread A\n");
-void *threadC(void *inutilise)
+static void *threadC(void *inutilise)
{
afficher(150, 'C');
printf("\n Fin du thread C\n");
{
afficher(150, 'C');
printf("\n Fin du thread C\n");
-void *threadB(void *inutilise)
+static void *threadB(void *inutilise)
{
pthread_t thC;
pthread_create(&thC, NULL, threadC, NULL);
{
pthread_t thC;
pthread_create(&thC, NULL, threadC, NULL);