[Glade-users] GTK+ threads: works great but compile-time warning



I found some people on the web who were putting a cast (GThreadFunc) before the 1st argument of 
g_thread_create. I did this, and got rid of the error message. Weird, and a little worrisome. Regardless, the 
code works.

But it occurs to me that maybe I don't need to do threads at all.
Here's specifically what I want to achieve:

I have the user press a button to begin some heavy computation, but I also want the user to be able to press 
another button, if desired, to stop the computation. They won't need to do anything else. That is, other than 
stop the computation, they need no more functionality while the numbers are being crunched.

I had tested briefly and found that once the computation started, I lost control and had to click on the x to 
close out the window. In Ubuntu, the screen darkens to inform the user that they've lost control. This is 
what initially led me to believe I needed threads.

Is there a way to allow them to stop the computation without resorting to threads? Seems like something a lot 
of programs would need, and I (perhaps mistakely) didn't think threads were quite so commonly used.

Dave

--- On Sat, 5/28/11, David Buchan <pdbuchan at yahoo.com> wrote:

From: David Buchan <pdbuchan at yahoo.com>
Subject: GTK+ threads: works great but compile-time warning
To: glade-users at lists.ximian.com
Date: Saturday, May 28, 2011, 8:58 PM
Hi guys,

Info: Ubuntu (lucid), gtkbuilder from glade 3.6.7, C
language with gcc.

I took some of Tadej's thread code from his Bits and Pieces
blog post, and modified it to closer to what I need.

Specifically, I moved the thread creation into a callback,
on the basis that I understood that all callbacks were
inside main's threadlock so it should be equivalent. I
removed the timeout.

You click on button1 and it's label will cycle from
"thread" to "cycle" each second. You click on button2 to
stop it.

It does the job, but gives a compile-time warning:

test5.c: In function ?on_button1_clicked?:
test5.c:33: warning: passing argument 1 of
?g_thread_create_full? from incompatible pointer type
/usr/include/glib-2.0/glib/gthread.h:225: note: expected
?GThreadFunc? but argument is of type ?void *
(*)(struct TestData *)?

Note that I call g_thread_create not g_thread_create_full.

Comments?
Code attached.

Thanks,
Dave




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