diff --git a/grid.c b/grid.c
index 697c04c6fd4bba7f56a04b95852d825663e090e4..140332fa4a8995bf40c117a7130ddbe5dd895431 100644
--- a/grid.c
+++ b/grid.c
@@ -28,7 +28,7 @@ void grid_collide( grid_t *g ) {
             else { node_fluid( &g->nodes[i][j] ); }
         }
     }
-    grid_propage(g);
+   
     grid_mod(g);
     printf("fini le calul\n");
 }
diff --git a/main.c b/main.c
index 31f42bc7fddffb7d09767357d656fbea6b3c7f88..5068aa73e0bf35d768bbbc7f7b4c2c05e3e157aa 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,5 @@
-#include <stdlib.h>
+#include "stdio.h"
+#include "stdlib.h"
 #include "grid.h"
 #include "mask.h"
 #include "node.h"
@@ -8,15 +9,15 @@
 
 grid_t g;
 SDL_Keycode escape = 0;
-//pathread_barrier_t b;
+pthread_barrier_t b;
+int n_thread = 0;
 sem_t lock;
 pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
 pthread_mutex_t mutexcalc = PTHREAD_MUTEX_INITIALIZER;
 struct gfx_context_t *ctxt;
-void *keyboad_control()
-{
+void *keyboad_control(){
    
-   pthread_mutex_lock(&mutex);
+   while(1){
    escape = gfx_keypressed();
    if (escape == SDLK_ESCAPE)
    {
@@ -24,37 +25,49 @@ void *keyboad_control()
       exit(0);
       
    }
-   pthread_mutex_unlock(&mutex);
-   sem_post(&lock);
+   }
+   
 }
 
 void *Calculate()
 {
    
-   pthread_mutex_lock(&mutex);
-   grid_collide(&g);
-   sem_post(&lock);
-   pthread_mutex_unlock(&mutex);
-  
+   
+   while (1)
+   {
+      
+      grid_collide(&g);
+      pthread_barrier_wait(&b);
+      grid_propage(&g);
+      pthread_barrier_wait(&b);
+      
+   }
    
 }
 void *Display(){
 
-   pthread_mutex_lock(&mutex);
-   gfx_present(ctxt);
+   sem_wait(&lock);
+   while (1)
+   {
+      
+      gfx_present(ctxt);
+  
+   }
    sem_post(&lock);
-   pthread_mutex_unlock(&mutex);
+   
+   
 } 
 int main(int argc, char *argv[])
 {
-   /*je trouve la barriere!!!! */
-   // pthread_barrier_init(&b);
+   
+   
    int x = atoi(argv[1]), y = atoi(argv[2]);
    TAU = atof(argv[3]);
    G = atof(argv[4]);
    double Gy = atof(argv[5]);
    const double rho = 1.0;
-   int n_thread = atoi(argv[6]);
+   n_thread = atoi(argv[6]);
+   pthread_barrier_init(&b, NULL,n_thread);
    int nthread_calcul = n_thread - 2;
    int rest, portion;
    pthread_t t_keyboard, t_display, t_calulator;
@@ -69,8 +82,7 @@ int main(int argc, char *argv[])
    }
    portion = atoi(argv[1])/nthread_calcul;
    rest = atoi(argv[1])%nthread_calcul;
-   while (1)
-   {
+   
       
       SDL_PumpEvents();
       SDL_ShowCursor(SDL_ENABLE);
@@ -79,17 +91,17 @@ int main(int argc, char *argv[])
       g.y = portion;
       for (int i = 0; i < nthread_calcul; i++)
       {
-      if (i == nthread_calcul -1)
-      {
+            if (i <= rest)
+               {
         
-         g.x +=  rest;
-         g.y +=  rest;
+         g.x = g.x + 1;
+         g.y = g.y + 1;
          
-      }
-      pthread_mutex_lock(&mutex);
+                }
+      
       pthread_create(&t_calulator, NULL, Calculate, NULL);
-      sem_wait(&lock);
-      pthread_mutex_unlock(&mutex);
+      
+      
       g.x += portion;
       g.y += portion;
       }
@@ -99,7 +111,7 @@ int main(int argc, char *argv[])
          perror("pthread_create");
          return EXIT_FAILURE;
       }
-      sem_wait(&lock);
+      
       g.x = x;
       g.y = y;
       render(ctxt, &g);
@@ -108,22 +120,24 @@ int main(int argc, char *argv[])
          perror("pthread_create");
          return EXIT_FAILURE;
       }
-      sem_wait(&lock);
+      
       gfx_left_right_mouse_pressed(&g);
       for (int i = 0; i < nthread_calcul; i++)
       {
           pthread_join(t_calulator, NULL);
       }
-      sem_destroy(&lock);
+      
      
-   }
+   
 
 
-   pthread_join(t_display, NULL);
-   pthread_join(t_keyboard, NULL);
-   sem_destroy(&lock);
-   gfx_destroy(ctxt);
-   grid_destroy(g);
+      pthread_join(t_display, NULL);
+      pthread_join(t_keyboard, NULL);
+      sem_destroy(&lock);
+      pthread_barrier_destroy(&b);
+      gfx_destroy(ctxt);
+      grid_destroy(g);
 
    return EXIT_SUCCESS;
 }
+