GTK threads and socket operations



Hi!

I am writing an application that periodically reads data from network sockets
(from Modbus enabled devices actually) and displays them in GTK+ application. I
read some tutorials about GTK threads and created a separate thread that
encompasses Modbus reads and updates to GTK labels:

modbus_thread = g_thread_new ("update_from_modbus",update_from_modbus,NULL);

The update_from_modbus() has a bunch of socket reads (inside xantrex_read_value())
and gtk_label_set_text()

sprintf(params_val_text,"%-5.1f (%4.1f Hz)\n%-4.1f\n%-4d",
0.001*xantrex_read_value(modbus_pointer,0x004C,RECONSTRUCT_YES),
0.01*xantrex_read_value(modbus_pointer,0x004E,RECONSTRUCT_YES),
0.001*xantrex_read_value(modbus_pointer,0x0054,RECONSTRUCT_YES),
xantrex_read_value(modbus_pointer,0x0052,RECONSTRUCT_YES));
gtk_label_set_text (GTK_LABEL(ac1_params_val),params_val_text);
gtk_label_set_justify(GTK_LABEL(ac1_params_val),GTK_JUSTIFY_LEFT);

However after several hours I see crashes when the program tries to reconnect to
my device. I tried to enclose GTK operations into gtk_threads_enter() /
gtk_threads_leave() but it has no effect. Can anyone, please explain what is
wrong here or may be point to a good example of multithreaded GTK code which has
network socket operations in it?

Thanks in advance,

-- Sergei


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