krähemann.com

Custom application design and development out-sourcing

AgsMainLoop new sync counter

As of GSequencer version 2.2.10, the synchronization overhead was drastically reduced. By introducing a new sync counter field to the AgsMainLoop implementations.

The prototype of the interface functions are as following:

void ags_main_loop_sync_counter_inc(AgsMainLoop *main_loop, guint tic);
void ags_main_loop_sync_counter_dec(AgsMainLoop *main_loop, guint tic);
gboolean ags_main_loop_sync_counter_test(AgsMainLoop *main_loop, guint tic);

Instead of traversing all the multi-threaded tree for all threads, to check if the current tic has been completed. The new sync counter is incremented or decremented at the right time within ags_thread_loop().

Yeah, it is more like a semaphore now, but with greater control over the synchronization work.

If we look at a multi-threaded synchronizing at a rate of 1000 Hz and e.g. 1000 threads doing synchronization. You soon recognize traversing the tree each tic causes a bottle-neck. So you get:

1000 * 1000 * 1000 = 1’000’000’000 checks per second

Whereas with a synchronization counter, you get the following:

1000 * 1000 = 1’000’000 checks per second

It is evident that 1 thread can check 1000 times per second a counter field. But 1 thread checking 1’000’000 per second the entire tree consisting of 1000 threads causes some real overhead.

The old strategy was preserved can be activated by setting the appropriate global to FALSE in ags/thread/ags_thread-posix.c:

static gboolean ags_thread_global_use_sync_counter = FALSE;

Enjoy the new algorithm.


by Joël