[prev in list] [next in list] [prev in thread] [next in thread]
List: gtkmm
Subject: Re: Need help with multi threading
From: kiet tran <vietory2g () gmail ! com>
Date: 2012-03-02 5:33:19
Message-ID: CAMJa5Bnd+CG0qsC7tk-z0CSHFUGx_V5+Ca-pz1oAHHCg=yx75g () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Thanks Robert I have created the loop in another thread and have
Gtk:dispatcher to trigger event back and forwd to the main thread.
Cheers,
Kiet Tran
On Thu, Mar 1, 2012 at 6:58 PM, Robert Pearce <rob@bdt-home.demon.co.uk>wrote:
> Hi kiet,
>
> On Thu, 1 Mar 2012 18:00:31 +1100 you wrote:
> >
> > I'm in a situation where I need to stay in a loop to listen for data from
> > the other end of socket connection, and at the same time I want to
> > update/display my GUI according to the information coming in.
> >
> OK
>
> > The GUI that going to display these informations is a pop-up diaglog box.
> >
> OK
>
> > So I think to fix this I need to spawn a thread for the pop-up diaglog
> box.
> >
> No, you don't. At least, that certainly isn't the ONLY solution, and in
> GTK it's almost certainly not the best or easiest solution either.
>
> The option I'd look at first is to remove the "stay in a loop" you
> first mentioned. Hook up your socket to a GIO::Channel (not sure on
> name, I use the unwrapped g_io_channel_... method) and then connect a
> handler to that channel's event signals. That way you can process the
> incoming data within the GLib/Gtk main loop. No need for threads at all.
>
> The other option to look at is to leave your whole GUI running in the
> main thread, but to launch your "loop to listen for data" into a second
> thread. That thread can then buffer the data and use a GLib::Dispatcher
> to trigger a main thread call-back to handle it (which I think is what
> GIO::Channel does internally on some platforms). Alternatively the
> socket thread could process the data and use a GLib::Dispatcher to
> trigger a dialog update. There's an example of this in the GLib-mm docs
> at gnome.org
>
> > Thus could some one please point me to some websites that show me how to
> > operate multi threading in gtkmm or sample code to get a simple one
> > running, thank-you.
> >
> www.gnome.org/docs/glibmm/group__Threads.html (or some variant of that
> - I'm looking at a local copy that was installed with the package)
>
> Rob
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list
>
[Attachment #5 (text/html)]
Thanks Robert I have created the loop in another thread and have Gtk:dispatcher to \
trigger event back and forwd to the main \
thread.<div><br></div><div>Cheers,</div><div><br></div><div>Kiet Tran<br><br><div \
class="gmail_quote"> On Thu, Mar 1, 2012 at 6:58 PM, Robert Pearce <span \
dir="ltr"><<a href="mailto:rob@bdt-home.demon.co.uk" \
target="_blank">rob@bdt-home.demon.co.uk</a>></span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">
Hi kiet,<br>
<div><br>
On Thu, 1 Mar 2012 18:00:31 +1100 you wrote:<br>
><br>
> I'm in a situation where I need to stay in a loop to listen for data \
from<br> > the other end of socket connection, and at the same time I want to<br>
> update/display my GUI according to the information coming in.<br>
><br>
</div>OK<br>
<div><br>
> The GUI that going to display these informations is a pop-up diaglog box.<br>
><br>
</div>OK<br>
<div><br>
> So I think to fix this I need to spawn a thread for the pop-up diaglog box.<br>
><br>
</div>No, you don't. At least, that certainly isn't the ONLY solution, and \
in<br> GTK it's almost certainly not the best or easiest solution either.<br>
<br>
The option I'd look at first is to remove the "stay in a loop" you<br>
first mentioned. Hook up your socket to a GIO::Channel (not sure on<br>
name, I use the unwrapped g_io_channel_... method) and then connect a<br>
handler to that channel's event signals. That way you can process the<br>
incoming data within the GLib/Gtk main loop. No need for threads at all.<br>
<br>
The other option to look at is to leave your whole GUI running in the<br>
main thread, but to launch your "loop to listen for data" into a second<br>
thread. That thread can then buffer the data and use a GLib::Dispatcher<br>
to trigger a main thread call-back to handle it (which I think is what<br>
GIO::Channel does internally on some platforms). Alternatively the<br>
socket thread could process the data and use a GLib::Dispatcher to<br>
trigger a dialog update. There's an example of this in the GLib-mm docs<br>
at <a href="http://gnome.org" target="_blank">gnome.org</a><br>
<div><br>
> Thus could some one please point me to some websites that show me how to<br>
> operate multi threading in gtkmm or sample code to get a simple one<br>
> running, thank-you.<br>
><br>
</div><a href="http://www.gnome.org/docs/glibmm/group__Threads.html" \
target="_blank">www.gnome.org/docs/glibmm/group__Threads.html</a> (or some variant of \
that<br>
- I'm looking at a local copy that was installed with the package)<br>
<br>
Rob<br>
_______________________________________________<br>
gtkmm-list mailing list<br>
<a href="mailto:gtkmm-list@gnome.org" target="_blank">gtkmm-list@gnome.org</a><br>
<a href="http://mail.gnome.org/mailman/listinfo/gtkmm-list" \
target="_blank">http://mail.gnome.org/mailman/listinfo/gtkmm-list</a><br> \
</blockquote></div><br> </div>
_______________________________________________
gtkmm-list mailing list
gtkmm-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtkmm-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic