Pulling threads of thread pool

AgsThreadPool serves you instantiated and running threads. To pull an AgsReturnableThread issue ags_thread_pool_pull(). The following example does instantiate a thread pool and starts it. After, it pulls two threads and the callbacks are invoked.

Example 3.2. Pulling threads of thread-pool

#include <glib.h>
#include <glib-object.h>

#include <ags/libags.h>

void thread_run_callback(AgsThread *thread, gpointer data);

void
thread_run_callback(AgsThread *thread, gpointer data)
{
  g_message("%s", (gchar *) data);
}

int
main(int argc, char **argv)
{
  AgsThread *main_loop;
  AgsThread *thread_0, *thread_1;
  AgsThreadPool *thread_pool;
  
  AgsApplicationContext *application_context;

  application_context = ags_thread_application_context_new();

  ags_application_context_prepare(application_context);
  ags_application_context_setup(application_context);
  
  main_loop = ags_concurrency_provider_get_main_loop(AGS_CONCURRENCY_PROVIDER(application_context));

  thread_pool = ags_thread_pool_new(main_loop);
  ags_concurrency_provider_set_thread_pool(AGS_CONCURRENCY_PROVIDER(application_context),
					   thread_pool);

  ags_thread_start(main_loop);
  ags_thread_pool_start(thread_pool);
  
  /* create thread 0 */
  thread_0 = ags_thread_pool_pull(thread_pool);
  
  g_rec_mutex_lock(AGS_RETURNABLE_THREAD(thread_0)->reset_mutex);

  g_atomic_pointer_set(&(AGS_RETURNABLE_THREAD(thread_0)->safe_data),
                       "thread 0");

  ags_returnable_thread_connect_safe_run(AGS_RETURNABLE_THREAD(thread_0),
                                         thread_run_callback);

  ags_returnable_thread_set_flags(thread_0,
				  AGS_RETURNABLE_THREAD_IN_USE);
    
  g_rec_mutex_unlock(AGS_RETURNABLE_THREAD(thread_0)->reset_mutex);

  /* create thread 1 */
  thread_1 = ags_thread_pool_pull(thread_pool);
  
  g_rec_mutex_lock(AGS_RETURNABLE_THREAD(thread_1)->reset_mutex);

  g_atomic_pointer_set(&(AGS_RETURNABLE_THREAD(thread_1)->safe_data),
                       "thread 1");

  ags_returnable_thread_connect_safe_run(AGS_RETURNABLE_THREAD(thread_1),
                                         thread_run_callback);

  ags_returnable_thread_set_flags(thread_1,
				  AGS_RETURNABLE_THREAD_IN_USE);
    
  g_rec_mutex_unlock(AGS_RETURNABLE_THREAD(thread_1)->reset_mutex);

  /*  */
  g_thread_join(main_loop->thread);
  
  return(0);
}