GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

multi threading in gtk

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
ramesh
Familiar Face


Joined: 16 Nov 2006
Posts: 40

PostPosted: Mon Apr 02, 2007 1:24 pm    Post subject: multi threading in gtk Reply with quote

hi all
i tried like this

void
on_button1_clicked ()
{
write2();
pthread_t thread2;
char *message1 = (char*)msg;
int iret2;

iret2 = pthread_create( &thread2, NULL, *write1, (void*) message1);

}
void *write1(void *ptr)
{
char *msg1;
msg1 = (char *) ptr;
printf("%s",msg1);
}
void write2()
{
//here is my gtk apllication(gui)
it has a buton to invoke the perticular thread

}

it has some big code
so here i given it short.
first i ve to run my gtk application.
it has a buton.
when i click the button, some thread has to be invoked.
here my problem is
after clicking the button my gtk(gui) application is hanging up to compltetion of
write1 ();
so it is taking long time to come original state(gtk application)
what i would like to do is
first i have to open the window.
and clicking the buttion,
invoking the thread,
with out hanging the window.

how can i do this

can you provide some example..

please help me in this way

thank you in advance
Back to top
hydra
Familiar Face


Joined: 23 Jan 2007
Posts: 35

PostPosted: Mon Apr 02, 2007 8:28 pm    Post subject: Reply with quote

Only one thread have to own the GUI control at a time. So, if you want to access GUI from several simultaneously running threads ..... you can not do that.
The main 2 ways to solve this is to use g_add_timeout () and g_thread_enter /g_thread_leave ()

And about the example... I have no such one now but tomorrow will check my sources..
Recently I found this site. http://www.gtk-server.org/index.html
This is Gtk server and it listenes for incomming connections on basic I/O files and pipes.
It is possible to write a Gtk application without to use C/C++ or any other programming language.. just write files, type commands and the application will be created. Cool!!
Back to top
ramesh
Familiar Face


Joined: 16 Nov 2006
Posts: 40

PostPosted: Tue Apr 03, 2007 5:13 am    Post subject: thank you for quick replay Reply with quote

HI
ONETHING.
I AM NOT USING THREADS IN MAIN LOOP
MAIN();
I WOULD LIKE TO USE THREADS IN SOME OTHER FUNCTION WHERE I NEED.

CAN U PLEASE HELP ME IN THIS WAY
THANK YOU IN ADVANCE
Back to top
hydra
Familiar Face


Joined: 23 Jan 2007
Posts: 35

PostPosted: Tue Apr 03, 2007 5:54 pm    Post subject: Reply with quote

You can create threads wherever you want. Have a look about this.
http://developer.gnome.org/doc/API/2.0/glib/glib-Threads.html
The function g_thread_create creates a thread for you and calls the functions associated with that thread.
But you should remeber that you should access any object of GTK only from one thread. 2 and more threads can not access GTK. GTK is accessable only for 1 thread. Have a closer look about Glib.
Here it is. http://developer.gnome.org/doc/API/2.0/glib/index.html
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP