title: Pause a running function pressing a button
body: <p>I have a gtk2+ code in which I have a running button and a stopping one. I want that the stop button pause the RUN function (not to leave it) in a specific point until run button is pressed again, continuing in the same point.</p>
  
  <p>The problem is that while loops block any kind of interaction with program interfaces and freezes.</p>
  
  <pre><code>void STOP(GtkWidget *widget, GObject *context_object_stop) 
  {
    stop=1; 
  }
  
  void RUN(GtkWidget *widget, GObject *context_object_run) 
  {
  
    GtkEntry *buffer= g_object_get_data (context_object_run, "buffer");
    GtkTextIter iter; 
    GtkTextMark *marker; 
    marker = gtk_text_buffer_get_insert(buffer);
    gtk_text_buffer_get_iter_at_mark(buffer, &amp;iter, marker);
  
    stop=0;
    int i=0;
  
      for (i=0; i&lt;5000000; i=i+1)
      {
       while (stop==1)
       {
         //here is my problem
       }
       gchar * stuff = g_strdup_printf("%d""\n", i);
       gtk_text_buffer_insert(buffer, &amp;iter, stuff, -1);
       g_free(stuff);
       while (gtk_events_pending())
       gtk_main_iteration();
       gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(wins), marker);
      }
  
  }
  </code></pre>
  
  <p>Any ideas to approach the solution?</p>
  
  <hr>
  
  <p>EDIT; An approach of multithreading that does not stop running the main function:</p>
  
  <pre><code>  stop=0;
    int i=0;
    pthread_t th1;
  
      for (i=0; i&lt;5000000; i=i+1)
      {
       void *StopRun(void *arg)
       {
       while (stop==1)
       {
         //here is my problem
       }
       }
       if (stop==1)
       {
       pthread_create(&amp;th1, NULL, (void*)StopRun, NULL);
       }
       gchar * stuff = g_strdup_printf("%d""\n", i);
       gtk_text_buffer_insert(buffer, &amp;iter, stuff, -1);
       g_free(stuff);
       while (gtk_events_pending())
       gtk_main_iteration();
       gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(wins), marker);
      }
  </code></pre>