Glib resume

Glib resume


Table of Contents

  • Overview of Glib
  • Glib's main event loop
  • Threads
  • Asynchronous Queues
  • Dynamic loading of Modules
  • Memory Management
  • IO Channels

1 Overview of Glib

The fully glib document was located in the glib website. This article is nothing but just repeat what I learned from above website. Or I consider this as an echo from mystery valley, because Glib is excellent, which provided both portability and elegant solution for the cross-system programer, it should be my base utilities in my daily programming life.

2 Glib's main event loop

I think the main event loop is the heart of the glib library, and it is the most import part of this library. So why? Because the event loop engine is always the critical and basic part of the architecture of a project. There are many paradigms of the architecture of event loop. Glib is based on reactor model which is also the most popular and developer friendly paradigm.

A reactor model can be separated into event source, event dispatch, and event process.
In Glib's event main loop, each source is associated with a GMainContext, A GMainContext can only be running in a single thread, but a source can be added and removed from anther threads.

3 Threads

The GThread API looks just a wrapper for POSIX Threads API, There are nothing so difference compared with pthread.

GThread provides a thread pool implementation, and its implementation details were not complicated. Following is the key points of its implementation:
  • It has a container(Queue) inside to store the task, which is usually an void point.
  • The another container is used to store the unused or free thread. In GThreadPool, it store the GTHreadPool itself, it has the proxy func used to run the task.

4 Asynchronous Queues

Asynchronous Queues provides asynchronous communication between threads. So the difference between it with other ordinary queues are that it has a thread safer mechanism inside. The implementation details of this thread safer mechanism are thread mutex and thread cond by POSIX standard of course.

5 Dynamic loading of Modules

Dynamic loading of Modules is the critical point in the Plug-in design paradigm, which can be concluded as the following formula:

Plug-In design = Dynamic loading modules + Interface design.

So I guess that's the purpose of this modules, to make the plug-in design into your project.

6 Memory Management

In the glib's documentation, there is two section related to Memory Management: Memory Allocation and Memory Slices.

Memory Allocation is nothing special here, it just provides a wrapper above the system implementation details. The benefit of those is to improve the portability just following the primary goal of GLib.

Memory Slices is real magic here, it is a memory management system, whose design target is not just the portability but the efficiency of memory management. I believe it's also the most complicated part of GLib.

7 IO Channels

GIOChannel is the wrapper layer above file descriptors, pipes, and sockets, which is the resources in programming. Beside its wrapper function, GIOChannel also can be added into Glib's default main loop context, which can be used to manage the resource, by g_io_create_watch or g_io_add_watch*.

Comments

Popular posts from this blog

Bluedroid stack in android

How to setup a NAT server?

Network programming in elisp