Re: signals and threads



Dmitry A. Yanko wrote:
Hi!

I develop the app, that needs to run 2 same windows, each in separate thread.
I have a same signal handlers in each thread. The difference is only in thread
specific data, because i need to make a different things in different threads.
Example:
...
g_signal_connect(G_OBJECT(app->text_buffer_my), "insert-text",
                    G_CALLBACK(on_tb_insert_text), NULL);
... g_print("tid: %p app->text_buffer_my: %p\n", pthread_self(),
  app->text_buffer_my);
...

Output:
tid: 0x8003 app->text_buffer_my: 0xb661ec18
tid: 0x4002 app->text_buffer_my: 0xb6627e40

But i have a problem with signal handlers. Only signal handler from
0x8003(registered 1st) thread invoked(for both buffers). But i need to handle
0x4002's "insert-text" with 0x4002 signal handler(to access thread specific
data and handle input properly). How can i resolve a problem?

Soooo,
    how many times do you envoke gtk_main() ?

I'm quite sure that running two gtk_main() functions
in the same program will undoubtedly result in good ol'
undefined behaviour ;) (that is, if you ever got it
to run in the first place)

A signal handler runs sychronously where the event
happens; i.e. the widget that fires "insert-text" will
call g_signal_emit() and when that returns; all
handlers will have been called.

Cheers,
                             -Tristan



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