Re: Drawing in separate thread to Gtk::DrawingArea



On Sat, 26 Jul 2014 19:50:58 +0300
Szőke Szabolcs <szabolcsx95 gmail com> wrote:

Hi everybody. I found the tutorial on gtkmm developer page about
multi-threading. But when I wanted to adapt for my needs, I couldn't
figure out how to do it. I have a DrawingArea widget within a window
and I want to do the drawing in separate thread because as the
drawing became more complex, the gui thread gets locked every time
when something is drawn. I know the theory: I should use a Dispatcher
to send the data to gui thread, but in tutorial I saw that when the
worker thread completed the job, the gui thread is notified. But I
can't do that, or at least I don't know how to do that in this
situation. Any help will be appreciated.


I don't know much about gtkmm or threads, but I would start by trying to
use a worker thread that sleeps until notified by the GUI thread, then
draws, and notifies the GUI thread that it's done and goes back to
sleep. It means both threads need to be able to notify each other.

Another (probably the "naive" approach) option is to spawn a worker
thread for each redraw. But I don't think it's good for scalability.

A possible problem is that the drawing is a GUI related operation, and
I'm not sure it's safe to draw to the Cairo surface from the worker
thread. I hope someone else here can clarify this point.

I'm not a regular gtkmm user though. This is just some basic ideas.


-- fr33


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