Re: Still confused on new thread starting idle functions to update UI.

2013-12-12 Thread Bernhard Schuster
The observed bad behavior is that sometimes messages don't appear at all, or appear twice in my textview. It's quite unpredictable. Sounds like a race condition. I spawn a thread from the main program - and from now on I don't talk about main - and this new thread prepares messages in a charac

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread Chris Angelico
On Thu, Dec 5, 2013 at 4:16 AM, Chris Vine wrote: > On Thu, 5 Dec 2013 03:06:59 +1100 > Chris Angelico wrote: >> See how much effort goes into >> making sure everything's thread-safe? [None], because this >> isn't even threaded - though it will happily handle any number of >> simultaneous clients

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread Chris Vine
On Thu, 5 Dec 2013 03:06:59 +1100 Chris Angelico wrote: [snip] > As promised, here's a simple Pike program that listens for socket > connections. > [snip] > > See how much effort goes into > making sure everything's thread-safe? The same amount, because this > isn't even threaded - though it will

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread Chris Angelico
On Thu, Dec 5, 2013 at 2:56 AM, David Buchan wrote: > PS. Socket programming is great fun! ( > http://pdbuchan.com/rawsock/rawsock.html ) Absolutely! I don't usually use raw sockets though - I tend to use TCP primarily, and sometimes UDP or ICMP, but not raw. TCP sockets equal MUD connections, wo

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread Chris Angelico
On Thu, Dec 5, 2013 at 2:56 AM, David Buchan wrote: > Making the pointer to textview global would indeed simplify things > enormously. I guess I avoid global variables like the plague, having been > told to for years. Also wanted to make the idle function generic. Yeah, lots of people have been t

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread David Buchan
On Thu, Dec 5, 2013 at 2:00 AM, David Buchan wrote: > > Things I've learned yesterday are: > > 1. strdup() (I've never seen or used it before) > 2. what the heck heap and stack mean (still more to learn there) > 3. a more general and flexible solution is probably to use asynchronous > message q

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread Chris Angelico
On Thu, Dec 5, 2013 at 2:18 AM, David Buchan wrote: > What I mean is, is it kosher to have: > > msgdatas msgdata; // I'd pass &msgdata as arg. to g_idle_add() I suppose. No, it's most definitely not, unless you can guarantee that (a) the function that called this will still be running when the i

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread Chris Angelico
On Thu, Dec 5, 2013 at 2:00 AM, David Buchan wrote: > > Things I've learned yesterday are: > > 1. strdup() (I've never seen or used it before) > 2. what the heck heap and stack mean (still more to learn there) > 3. a more general and flexible solution is probably to use asynchronous > message que

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread David Buchan
On Wed, Dec 4, 2013 at 2:59 PM, David Buchan wrote: >  // Allocate memory on the heap, not stack. >  msgdata = (msgdatas *) malloc (1 * sizeof (msgdatas)); >  msgdata->textview = (int *) malloc (1 * sizeof (int)); >  message = (char *) malloc (1024); The only blocks of memory that need to b

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread David Buchan
On 4 December 2013 13:31,  wrote: > Here's a tiny, complete program that does almost what you want. It's > gtk2, but should work fine with gtk3. > > http://pastebin.com/PsG2UDkY > > It just updates a status bar, but it'd be easy to make it do a textview > instead. > > John

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread jcupitt
Oh dear, I think my attachment got munched (thanks Chris). Try here: http://pastebin.com/PsG2UDkY On 4 December 2013 13:31, wrote: > Here's a tiny, complete program that does almost what you want. It's > gtk2, but should work fine with gtk3. > > It just updates a status bar, but it'd be easy

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread jcupitt
Here's a tiny, complete program that does almost what you want. It's gtk2, but should work fine with gtk3. It just updates a status bar, but it'd be easy to make it do a textview instead. John ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread David Buchan
On Tue, 3 Dec 2013 19:59:22 -0800 (PST) David Buchan wrote: > ok, I may be getting somewhere. I did some reading on heap memory > versus stack. > > Here's a vastly simplified example program which doesn't use GTK+, > but I'm using to demonstrate my plan of attack. > > I use a function called p

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread Chris Angelico
On Wed, Dec 4, 2013 at 9:28 PM, Chris Vine wrote: > Otherwise, have you considered perhaps using something like the python > bindings for GTK+? These have a binding for g_idle_add() and handle > all the memory allocation for you. I recommend using the > gobject-introspection binding for GTK+-3 r

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread Chris Vine
On Tue, 3 Dec 2013 19:59:22 -0800 (PST) David Buchan wrote: > ok, I may be getting somewhere. I did some reading on heap memory > versus stack. > > Here's a vastly simplified example program which doesn't use GTK+, > but I'm using to demonstrate my plan of attack. > > I use a function called pac

Re: Still confused on new thread starting idle functions to update UI.

2013-12-04 Thread Chris Angelico
On Wed, Dec 4, 2013 at 2:59 PM, David Buchan wrote: > // Allocate memory on the heap, not stack. > msgdata = (msgdatas *) malloc (1 * sizeof (msgdatas)); > msgdata->textview = (int *) malloc (1 * sizeof (int)); > message = (char *) malloc (1024); The only blocks of memory that need to be

Re: Still confused on new thread starting idle functions to update UI.

2013-12-03 Thread David Buchan
ok, I may be getting somewhere. I did some reading on heap memory versus stack. Here's a vastly simplified example program which doesn't use GTK+, but I'm using to demonstrate my plan of attack. I use a function called packit() which allows me to still use strdup(). Comments? Dave Valgrind i

Re: Still confused on new thread starting idle functions to update UI.

2013-12-03 Thread David Buchan
David Buchan wrote: [snip] > It is awkward, and probably unnecessary.  Unless you have a very good > reason, that is not the way to do it.  Pass the idle function a string > allocated on the heap, and free it in the idle function when finished > with.  Any other way creates thread dependencies w

Re: Still confused on new thread starting idle functions to update UI.

2013-12-03 Thread Chris Vine
On Tue, 3 Dec 2013 13:15:28 -0800 (PST) David Buchan wrote: [snip] > It is awkward, and probably unnecessary.  Unless you have a very good > reason, that is not the way to do it.  Pass the idle function a string > allocated on the heap, and free it in the idle function when finished > with.  Any o

Re: Still confused on new thread starting idle functions to update UI.

2013-12-03 Thread David Buchan
David Buchan wrote: > These darn threads and idle functions still baffle me. I'm sorry to > be such a pest. > > I want to periodically update a textview as new information comes > available. Sometimes this information can come in quickly (roughly > every tenth of a second). Each update is a

Re: Still confused on new thread starting idle functions to update UI.

2013-12-03 Thread Chris Vine
On Tue, 3 Dec 2013 11:02:53 -0800 (PST) David Buchan wrote: > These darn threads and idle functions still baffle me. I'm sorry to > be such a pest. > > I want to periodically update a textview as new information comes > available. Sometimes this information can come in quickly (roughly > every t

Re: Still confused on new thread starting idle functions to update UI.

2013-12-03 Thread Andrew Potter
On Tue, Dec 3, 2013 at 11:02 AM, David Buchan wrote: > These darn threads and idle functions still baffle me. I'm sorry to be such a > pest. > I want to periodically update a textview as new information comes available. > Sometimes this information can come in quickly (roughly every tenth of a

Still confused on new thread starting idle functions to update UI.

2013-12-03 Thread David Buchan
These darn threads and idle functions still baffle me. I'm sorry to be such a pest. I want to periodically update a textview as new information comes available. Sometimes this information can come in quickly (roughly every tenth of a second). Each update is a single line of text. The observed