GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Mon Sep 22, 2014 10:18 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: multi threading in gtk
PostPosted: Mon Apr 02, 2007 1:24 pm 
Offline
GTK+ Guru

Joined: Thu Nov 16, 2006 5:08 am
Posts: 259
Location: INDIA
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 02, 2007 8:28 pm 
Offline
Familiar Face

Joined: Tue Jan 23, 2007 6:13 pm
Posts: 34
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!!


Top
 Profile  
 
 Post subject: thank you for quick replay
PostPosted: Tue Apr 03, 2007 5:13 am 
Offline
GTK+ Guru

Joined: Thu Nov 16, 2006 5:08 am
Posts: 259
Location: INDIA
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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 5:54 pm 
Offline
Familiar Face

Joined: Tue Jan 23, 2007 6:13 pm
Posts: 34
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group