Dear all, I am writing a simple C application which involves GTK+ libraries to generate the GUI. However, I have encountered a problem regarding the periodic display of numbers in the spin buttons. The program is quite simple. It is only consisted of one button and a spin button. When I clicked the button, it will trigger a thread to start running as a simple counter from 1 to 100 with sleeping for 1s after each count. The expected result should be the spin button start changing value from 1 to 100 each second. However, it is not the case. The values are not just updated as frequently as expected. Sometimes, it will rise steadily while most of times, it just stopped at certain value and then jump directly to another value after a while. I created 3 threads for this program: 1. main thread: which stored declaration of some global variables. 2. gui thread, which initialize the GUI like gtk_init(NULL, NULL) and gtk_main(); 3. counter thread, which is the simple counter thread; the function of the counter thread is: GtkWidget *spin_button; double i ; spin_button = lookup_widget(window1, “spin_button1”); // I am using glade to produce the GUI so I
have to use this lookup_widget
function /* the thread will wait for cond_variables, which is sent when user press the button of GUI */ for (i = 0; i<200; i++) sleep(1); } in fact, I have to write an application that requires a constant updates of data and the problem mentioned above is quite a big headache for me. Would u please help me? Thanks very much P.S if you need detailed info, please feel free to say, I will post it ASAP.
Michael Lam |