title: Using Gstreamer with pthreads
body: <p>I've read most of the documentation about Gstreamer and how to use it, but there's very little explained about combining Gstreamer and other non
  gstreamer-related threads. </p>
  
  <p>So I'm trying to create a simple application where on one thread I have a simple pipeline with a source element connected directly to  a sink element. I'm using "pthread" library to manage the threads. Then I create another pthread to handle the other parts of the program.</p>
  
  <p>To do this I'm using this example (<a href="http://www.thegeekstuff.com/2012/04/create-threads-in-linux/?utm_source=feedburner" rel="nofollow noreferrer">http://www.thegeekstuff.com/2012/04/create-threads-in-linux/?utm_source=feedburner</a>).</p>
  
  <p>Here is the program:</p>
  
  <pre><code>#include&lt;gst/gst.h&gt;
  
  #include&lt;stdio.h&gt;
  #include&lt;string.h&gt;
  #include&lt;pthread.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;unistd.h&gt;
  
  pthread_t tid[2];
  
  void* doSomeThing(void *arg)
  {
      GMainLoop *loop;
  
      printf("\n Completed. \n");
  
      GstElement *pipeline;
  
      loop = g_main_loop_new (NULL, FALSE);
  
      pipeline = gst_parse_launch ("gst-launch v4l2src ! xvimagesink", NULL);
  
      gst_element_set_state (pipeline, GST_STATE_PLAYING);
  
      g_main_loop_run (loop);
  
      gst_element_set_state (pipeline, GST_STATE_NULL);
  
      gst_object_unref (GST_OBJECT (pipeline));
  
      g_main_loop_unref (loop);
  
      return NULL;
  }
  
  int main(int argc, char *argv[])
  {
      gst_init (&amp;argc, &amp;argv);
  
      pthread_create(&amp;(tid[0]), NULL, &amp;doSomeThing, NULL);
  
      return 0;
  }
  </code></pre>
  
  <p>So I compile. No errors. When I run it, it doesn't open any windows and doesn't start streaming or anything. I have the feeling that's it's the way I'm creating my pipeline thread. So bottomline is I don't have a good knowledge of Gstreamer and any help is much appreciated.</p>
  
  <p>(Notice that in the previous code I omitted the creation of the second thread since the problem is that the pipeline isn't streaming.)</p>