| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 
 |  
#include <stdio.h>
#include <stdlib.h>
#include "io.h"
#include "pthread.h"
#define MAX 100
void print(char *nbr, int value);
void *boucle1(void *p_data);
void *boucle2(void *p_data);
void *boucle3(void *p_data);
void *boucle4(void *p_data);
void *boucle5(void *p_data);
void *boucle6(void *p_data);
void *boucle7(void *p_data);
void *boucle8(void *p_data);
int main(void)
{
 pthread_t thread_boucle1, thread_boucle2;
 pthread_t thread_boucle3, thread_boucle4;
 pthread_t thread_boucle5, thread_boucle6;
 pthread_t thread_boucle7, thread_boucle8;
 /* first part */
 pthread_create(&thread_boucle1, NULL, boucle1, NULL);
  pthread_create(&thread_boucle2, NULL, boucle2, NULL);
  pthread_join(thread_boucle1, NULL);
  pthread_join(thread_boucle2, NULL);
 /* next part */
  pthread_create(&thread_boucle3, NULL, boucle3, NULL);
  pthread_create(&thread_boucle4, NULL, boucle4, NULL);
  pthread_join(thread_boucle3, NULL);
  pthread_join(thread_boucle4, NULL);
 /* next part */
  pthread_create(&thread_boucle5, NULL, boucle5, NULL);
 pthread_create(&thread_boucle6, NULL, boucle6, NULL);
  pthread_join(thread_boucle5, NULL);
  pthread_join(thread_boucle6, NULL);
  /* last part */
  pthread_create(&thread_boucle7, NULL, boucle7, NULL);
 pthread_create(&thread_boucle8, NULL, boucle8, NULL);
  pthread_join(thread_boucle7, NULL);
  pthread_join(thread_boucle8, NULL);
 /* the end */
 pause("PRESS ENTER");
  return 0;
}
void print(char *nbr, int value)
{
  char nameOfFile[16] = "thread.txt";
 FILE *myFile = fopen(nameOfFile, "w");
 if(myFile != NULL)
 {
  fprintf(myFile, "%s %i\n", nbr, value);
  fprintf(stdout, "(%s) %i\n", nbr, value);
    fflush(stdout);
 }
 else
 {
  fprintf(stderr, "Erreur : myFile = NULL");
 }
 fclose(myFile);
}
void *boucle1(void *p_data)
{
 char nbr = '1';
 int i =0;
 for(i=0;i<MAX;i++)
 {
   print(&nbr, i);
 }
 (void) p_data;
 return NULL;
}
void *boucle2(void *p_data)
{
  char nbr = '2';
 int i = 0;
 for(i=0;i<MAX;i++)
 {
   print(&nbr, i);
 }
 (void) p_data;
 return NULL;
}
void *boucle3(void *p_data)
{
  char nbr = '3';
  int i = 0;
 for(i=0;i<MAX;i++)
 {
   print(&nbr, i);
 }
 (void) p_data;
 return NULL;
}
void *boucle4(void *p_data)
{
  char nbr = '4';
  int i = 0;
 for(i=0;i<MAX;i++)
 {
   print(&nbr, i);
 }
 (void) p_data;
 return NULL;
}
void *boucle5(void *p_data)
{
  char nbr = '5';
  int i = 0;
 for(i=0;i<MAX;i++)
 {
   print(&nbr, i);
 }
 (void) p_data;
 return NULL;
}
void *boucle6(void *p_data)
{
  char nbr = '6';
  int i = 0;
 for(i=0;i<MAX;i++)
 {
   print(&nbr, i);
 }
 (void) p_data;
 return NULL;
}
void *boucle7(void *p_data)
{
  char nbr = '7';
  int i = 0;
 for(i=0;i<MAX;i++)
 {
   print(&nbr, i);
 }
 (void) p_data;
 return NULL;
}
void *boucle8(void *p_data)
{
  char nbr = '8';
  int i = 0;
 for(i=0;i<MAX;i++)
 {
   print(&nbr, i);
 }
 (void) p_data;
 return NULL;
} | 
Partager