[Gtk-sharp-list] ThreadNotify: The saga continues

Pablo Baena pbaena@uol.com.ar
25 Oct 2002 22:56:15 +0000


--=-W09IdzrCJCtqdz613Mbo
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hello,
Yes, maybe I should avoid using threads, I know it is difficult to debug
them.

My main use for threads is for launching processes and monitoring its
status with the progress bar, while keeping my window attending the
normal events. I guess that I could get around this using a function
with gtk_timeout_add in the main loop that checks some pipe (or queue)
that informs the status (borrowed the idea from gcombust ;).

Do you suggest anything better for this.

On Fri, 2002-10-25 at 16:22, Miguel de Icaza wrote:

    Hello!
    
    > I've been using Gtk# for a while now, got the usual stumbling blocks
    > but ultimately everything fits together. However, I have come to
    > realize something that I think is annoying from the point of view of a
    > user. That is, ThreadNotify. I've used it for a while and it served
    > its purpose very well for some time. When my small project got a
    > little bigger and I made a little heavier use of threads for the
    > different tasks, my code just started to became uglier and uglier, and
    > just because I had to use ThreadNotify everytime I needed to make the
    > smallest change to the widgets. 
    > 
    > I was wondering if there is a plan to make the libraries thread safe,
    > not in the sense of insert mutexes for everything in Gtk (something I
    > think is the responsability of the user), but to allow getting the job
    > done without ThreadNotify. 
    
    The problem as you well point out is that Gtk is not thread safe, and
    making it thread safe will be very complex.  In fact, Gtk is thread
    aware already and has some limited support for thread, but it is very
    complicated code.  It would also slow down Gtk a lot for the average
    user.
    
    Most Gtk programs are event-driven programs.  Even driven programs are a
    lot simpler to debug than multi-threaded applications.  In general, my
    suggestion is to only use threads when you absolutely have to because
    they bring a level of complexity that most of the time you can avoid. 
    You might for instance want to read John Ousterhout's notes for his
    Usenix keynote on `Why threads are a bad idea (most of the time)' or
    something like that. 
    
    Maybe you could explain what your program does, and why you need to use
    so many threads?
    
    Miguel
    

--=-W09IdzrCJCtqdz613Mbo
Content-Type: text/html; charset=utf-8

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/1.0.4">
</HEAD>
<BODY>
Hello,
<BR>
Yes, maybe I should avoid using threads, I know it is difficult to debug them.
<BR>

<BR>
My main use for threads is for launching processes and monitoring its status with the progress bar, while keeping my window attending the normal events. I guess that I could get around this using a function with gtk_timeout_add in the main loop that checks some pipe (or queue) that informs the status (borrowed the idea from gcombust ;).
<BR>

<BR>
Do you suggest anything better for this.
<BR>

<BR>
On Fri, 2002-10-25 at 16:22, Miguel de Icaza wrote:
    <BLOCKQUOTE>
<PRE><FONT COLOR="#737373"><FONT SIZE="3"><I>Hello!</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I></FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>&gt; I've been using Gtk# for a while now, got the usual stumbling blocks</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>&gt; but ultimately everything fits together. However, I have come to</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>&gt; realize something that I think is annoying from the point of view of a</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>&gt; user. That is, ThreadNotify. I've used it for a while and it served</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>&gt; its purpose very well for some time. When my small project got a</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>&gt; little bigger and I made a little heavier use of threads for the</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>&gt; different tasks, my code just started to became uglier and uglier, and</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>&gt; just because I had to use ThreadNotify everytime I needed to make the</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>&gt; smallest change to the widgets. </FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>&gt; </FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>&gt; I was wondering if there is a plan to make the libraries thread safe,</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>&gt; not in the sense of insert mutexes for everything in Gtk (something I</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>&gt; think is the responsability of the user), but to allow getting the job</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>&gt; done without ThreadNotify. </FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I></FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>The problem as you well point out is that Gtk is not thread safe, and</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>making it thread safe will be very complex.  In fact, Gtk is thread</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>aware already and has some limited support for thread, but it is very</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>complicated code.  It would also slow down Gtk a lot for the average</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>user.</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I></FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>Most Gtk programs are event-driven programs.  Even driven programs are a</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>lot simpler to debug than multi-threaded applications.  In general, my</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>suggestion is to only use threads when you absolutely have to because</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>they bring a level of complexity that most of the time you can avoid. </FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>You might for instance want to read John Ousterhout's notes for his</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>Usenix keynote on `Why threads are a bad idea (most of the time)' or</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>something like that. </FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I></FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>Maybe you could explain what your program does, and why you need to use</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>so many threads?</FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I></FONT></FONT></I>
<FONT COLOR="#737373"><FONT SIZE="3"><I>Miguel</FONT></FONT></I>
</PRE>
    </BLOCKQUOTE>
</BODY>
</HTML>

--=-W09IdzrCJCtqdz613Mbo--