Re: [gtkmm] 2 mainloops in 2 different threads?



> >I am pretty sure, that I do not actually need two main loops, but I face
> >the problem, that the library can be incorporated into a a GUI programm or
> >or simple "script like programm", that has no main loop in the first
> >thread. I nevertheless need to service the database link. So either the
> >programm has two main loops (one doing whatever the user wants it to do
> >(Gui, ...) and the second connected to the database) or just one mainloop
> >(connected to the database). The library should be the same for both
> >szenarios. And thats why I came to this solution. I believe (I do stress
> > the word believe - I do not know for sure), that possibly having two
> > mainloops is not the worst solution to this problem. I am always willing
> > to have a look at other possible solutions - e.g. "Model-View-Controller"
> > and I am very grateful, that you have pointed out this concept.
>
> ok, now i understand why you have two main loops. whether you really
> need them or not depends mostly on whether there are any real-time
> aspects to the database operation. by real-time, i mean "time
> constrained".
>
> if not (and i suspect that this is the case), then you should be able
> to just hook the database code into the GUI main loop by providing an
> API for the library that:
>
>     1) exposes 1 or more file descriptors that can be polled for
>          "read possible" or "write possible"
>     2) callbacks to be executed when either of these conditions
>          occurs.
>

I have done something similar. Actually, the main reason of choosing gtkmm 
instead of Qt was that gtkmm can more easily extend its main loop to include 
some custom polling algorithm. Unforunatelly I haven't ported to any recent 
gtkmm ver. still.
There is some issues I had to deal with. One of them is that you have to 
choose between two mechanisms:
- multi-thread, where you have to use data-locking to avoid corruption
or
- single-process, where you will most probably deal with re-entrancy in 
functions.
Please ask in personal for more details.




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