Re: [gtkmm] Concurrency with gtk/gtkmm



Many thanks for your reply.

I think I was not clear enough in my first email.

Tassos Bassoukos wrote:
On Mon, 2002-11-11 at 20:57, Enrico Costanza wrote:

[snip]

Up to now I have used idle function successfully to avoid GUI to freeze. I have tryed to use 2 idle functions hoping that this would simply and efficently put the two functions in parallel execution, but this does not work. One of the two is blocked. I have tryed a variety of values for the priority of the two (both 0, both a higher number, one lower and one higher value..).

First of all I wander: why is this not working?


Beacuse you are using two idle functions.
You do not need to monitor the user interface, the main loop takes care
of that for you atomatically. You just need to create and hook up your
idle function, which should do some not too time-consuming processing.
You then connect signal handlers to events, which (if that event is
triggered) will be called between calls to your idle function.

So, does that mean that only one idle function per time is allowed in gtk?




As an example, say you have a process that goes on and on I (say,
calculating the numbers of pi), and a button called "Stop". The button,
when clicked, will set a variable named f.e. "stop_calculations".
In the idle function, the code checks this variable, and if set will
return "false" to remove itself as an idle handler. If not set, it will
calculate the next digit of pi and return true, to remain as an idle
handler..

That is ok, but my problem is that I need to monitor another (external) user interface (not gtk) and process some data at the same time. I actually have (or wish to have) 3 things going on at the same: the gtk GUI, an external interface and a (sound) processing task.

I managed to have the first 2 running smootly, but I had lots of problems when I tried to add the 3rd one.



Also what should I then use to have 2 or more processes in parallel?
I have seen that glib supports threads, and I have also seen POSIX.
Is there any (dis)advantage in using one or the other with gtk/gtkmm?
(I have read that gtk is not thread safe, what does this mean in practice?)


This means that you should not call Gtk+ (and therefore Gtkmm) code from
two threads at the same time. You *can* have a thread for handling the
UI and one (or more) for the other processing you need to do.

Glib supprts threads and the associated infrastructure, but you will
still need to create code that uses them.

Does that mean that Glib is not enough to have concurrency, but that I need (for example) Glib in addition to POSIX?


Is there any other option that i should consider?
(for this particular situation of monitoring an input, would it be worth to consider implmenting my own set of signals & handlers?)


It depends on your timing constraints. Are 10 ms delays acceptable?
100ms?  100us?

My supposed bottleneck is at about 120ms, so this should be my target.
Thanks again,
Enrico Costanza




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]