Re: Re: Losing GtkTextBuffer when threading
- From: Dan McKinnon <dan danmckinnon net>
- To: gtk-app-devel-list gnome org
- Subject: Re: Re: Losing GtkTextBuffer when threading
- Date: Tue, 11 Oct 2005 20:02:04 -0700
Alan M. Evans wrote:
On Mon, 2005-10-10 at 19:51, Dan McKinnon wrote:
typedef struct networktype{
...
GtkTextBuffer *output_buffer;
..
} networktype;
void append_to_buffer( GtkTextBuffer *output_buffer, char *text ){
GtkTextIter output_end;
gtk_text_buffer_get_end_iter( output_buffer, &output_end );
gtk_text_buffer_insert( output_buffer, &output_end, text, -1 );
}
int net_init( networktype *net, GtkTextBuffer *buf ){
net->output_buffer = buf;
append_to_buffer( net->output_buffer, "Initilizing Network\n");
...
}
void *net_thread( void *args ){
...
append_to_buffer( net->output_buffer, "Getting host by name\n");
}
in the main function I've done everything right, as far as I know:
g_thread_init( NULL );
gdk_threads_init();
gdk_threads_enter();
net_init( &net, txtoutput_buffer);
pthread_create( &net->thread, NULL, net_thread, &net );
What's going on here?
Is there anywhere a call to gtk_text_buffer_new() ?
I'm using GLADE to generate the code. I'm using windows pthreads.
To get txtoutput_buffer I'm using the glade-generated function
lookup_widget( GTK_WIDGET(windowMain), "txtOutput" );
So just to re-cap, here's what's going on
Main:
1. Aquire GtkTextBuffer and put a pointer to it inside a struct
2. Output some text to the buffer (using the pointer in the struct as the reference)
3. Start a new thread, passing the struct with the pointer to the buffer in it
Inside the thread:
1. Output to the buffer
Outputting to the buffer works fine until it gets to the thread.
I don't think it's likely to be a racing issue, but since I hardly ever write
threaded applications I don't know all the symptoms that come about from racing.
I know however that the buffer is properly initialized before the thread kicks in
/and/ the buffer is not modified at any other time except during and before the thread start up.
Thoughts? Solutions?
Thanks.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]