On Tue, Apr 30, 2013 at 12:01 PM, Patrick Ohly <patrick.ohly@xxxxxxxxx> wrote:
On Tue, 2013-04-30 at 10:44 +0100, jcupitt@xxxxxxxxx wrote:This is one-way. How about two-way communication between threads?
> You can do this very simple and reliably. For example:
>
> worker()
> {
> char *str;
>
> for(;;) {
> str = g_strdup("hello world!\n");
> g_idle_add(from_worker_cb, str);
> sleep(1);
> }
> }
>
> gboolean
> from_worker(char *str)
> {
> update_textview(str);
> g_free(str);
> return FALSE;
> }
asynchronous queues are your friend here... one of two ways:
- have a thread that reads the async queue, followed by the appropriate call depending on the message read, where all other threads write to the Q.
or - two async queues, one in each thread, where each is a read/write of the other
this would depend on the how much you need here. between only two threads you could get away with the 2nd option. more than that, and you should go with the first.
_______________________________________________ gtk-list mailing list gtk-list@xxxxxxxxx https://mail.gnome.org/mailman/listinfo/gtk-list