0

I have a simple system in which there is a GList structure. There are two threads: say Head() that causes ingress of data into the GList structure. Another thread Tail() causes egress of data (and its processing) at tail end of the list.

I was going to implement this originally using pthreads, but the glib documentation itself suggested that instead of threads a main loop with context should be used for attaching sources and dispatching callbacks.

In general it wasn't clear what problems the glib main loop, main context and source system attempts to solve. All I could gather is it that it finds applications in reading socket data, its parallelism with poll() and the UI eventing system.

What is the use case of GlibMainLoop system? In terms of my problem statement is it applicable?

Ace
  • 1,501
  • 4
  • 30
  • 49

1 Answers1

4

GLib is part of the Gnome project. It was built first and foremost with GUI applications in mind, though it's not limited to that use. Its model for GUI programming is a typical event-based one, driven by a main loop that receives events and dispatches them appropriately to components. You should interpret the documentation in that light.

It sounds like yours is not a GUI application, with its only GLib association being its use of a GList. I find GList a bit of a questionable choice in that context, but not necessarily a wrong one. Choosing GList does not mean you should commit to an event-driven program design, and if you don't then you probably have no use for a GLib main event loop.

Nevertheless, an event-driven design might serve you well, and in some ways it would be simpler than a multithreaded one. Much depends on the details of what your producer and consumer are supposed to do.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157
  • Amazing info. My platform will primarily be a data processor with no GUI (For now at least). It ingresses bluetooth data and perhaps vision data and then tries to rapidly synthesize it and take AI based action from that data. – Ace Jun 28 '19 at 16:48
  • So yeah from what you are saying I am really happy to fallback to elementary structures. Perhaps the only other great use of GLib is ThreadPools which is hard to implement by hand. – Ace Jun 28 '19 at 16:49