Chapter 3. Multi-/Super-threaded tree

Table of Contents

The main loop interface
Threads in general
Pulling threads of thread pool
Worker-threads to do tic-less parallelism
Asynchronously destroy objects
Launching tasks
Async message delivery

Advanced Gtk+ Sequencer comes with an AgsThread object. It is organized as a tree structure. The API provides many functions to work with it. These threads do the ::clock event where all threads synchronize.

The AgsTaskLauncher runs synchronized as well but is going to be waited after syncing to run all tasks. The AgsTask signal ::launch runs asynchronous exclusively. Every thread tree shall have at toplevel a thread implementing AgsMainLoop interface.

There is an object call AgsThreadPool serving prelaunched threads. It returns on pull AgsReturnableThread instances. They can be used with a callback ::safe-run.

There is a interface to implement by your application context. Thus the AgsConcurrencyProvider interface is used. It has some common get/set functions to do basic multi-threaded work by well defined objects.

The main loop interface

AgsMainLoop should be implemented by toplevel threads. Within a thread tree this is the topmost element. It has various get and set methods you would expect.

To control the AgsThread::clock signal AgsMainLoop's methods are going to be invoked. The involved functions are:

As it shall be implemented by AGS_TYPE_THREAD subtypes, this parent object provides a mutex to properly lock the object. You should obtain the GRecMutex pointer by accessing its field:

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

#include <ags/libags.h>

AgsThread *thread;

GRecMutex *thread_mutex;

thread = ags_thread_new(NULL);

/* get object mutex */
thread_mutex = AGS_THREAD_GET_OBJ_MUTEX(thread);