Re: [[gtkmm] Glib::RefPtr also for Widgets?]



On Mon, 2002-09-23 at 16:28, Paul Davis wrote:
> 
> i can't recall the specific set that i've had problems with, but it
> includes buttons, clists and windows.

My dialog is derived from Gtkmm::Window

> >I have multithreaded program, but only the main thread uses gtk/gtkmm.
> >Other threads are workers only. And what do you mean by "one where memory
> >allocation might happen after the "delete this" but before the end of
> >signal emission" ? 
> 
> 	thread 1:                          thread 2:
>         ---------------------------------------------
> 	start signal emission
> 	delete this
> 					   new Foo;
> 
>         finish signal emission					   
> 
> there is every chance that the memory associated with the widget for
> which the signal emission was occuring has been reused for a "Foo".

This surely happens in my code, because my worker thread does some
things with std::strings and they alloc memory... And I've never
experienced a crash that could be caused by this thing, but I'll do some
more tests with heavier thread load :)

> 		    Of course 'delete this' is called in main thread where
> >windows are created and signals are handled, and of course when I delete
> >this object I don't alloc any memory in this thread. But other threads are
> >free to do it and they surely do allocs.
> 
> unless you are using a highly customized version of malloc(3) such as
> libhoard or the (terrible) one that comes with linuxthreads but is not
> used by default, memory released by one thread can be reused by another.

No, I use standard libraries. I don't know if is is important in this
case but I use g++ 3.2 with libstdc++ supporting threads. Perhaps it
adds some additional level of security?

> >> deleting a widget during a signal emission is just a bad idea, IMHO.
> >
> >You can always do a little trick:
> >In signal handler add a timer callback and bind 'this' pointer as a param
> >to the callback, and the only thing that callback does is 'delete param'
> >:)
> 
> thats what the template function i showed did, except it uses the idle
> callback, not a timer. 

Honestly I didn't track this thread from the beginning and I didn't see
your previous posts. And of course suggesting timer instead of idle was
my mistake, I thought about idle :)

-- 
struct Sig {
  string name("     J a r e k   D u k a t     ");
  string mail(" madmaxer (at) poczta (dot) fm ");
};


----------------------------------------------------------------------
Wykorzystaj mnie... >>> http://link.interia.pl/f1654





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