Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: Do I need threading for my GUI?

by shmem (Chancellor)
on Feb 19, 2008 at 10:00 UTC ( [id://668765]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Do I need threading for my GUI?
in thread Do I need threading for my GUI?

This is probably the reason why many of us say "don't use threads for this task".

Stick with the framework. It doesn't use threads and is event based? Don't use threads, use events, then. The problem can be solved within the same framework, without adding threads into the mix. Starting a long running sub prevents Tk from servicing other events? Make sure your sub cooperates and yields time slices to Tk.

I'm not saying that it is a bad idea to use Tk within a threaded application, but that it is probably not so good an idea to use threads within Tk, since the framework itself is threads-unaware and probably not programmed in a thread-safe way; so using threads within it requires good understanding of the working of both perl threads and Tk.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^4: Do I need threading for my GUI?
by BrowserUk (Patriarch) on Feb 19, 2008 at 13:48 UTC
    This is probably the reason why many of us say "don't use threads for this task".

    Even though you admit to having made little (no?) use of threads?

    If you encountered a bug in a regex, that allowed the regex to work but causes a warning during global destruction, would you advocate the replacement of all regexes using character by character comparisons and huge if/else cascades?

    Eg. You'd advocate if( $string =~ m[C\d\[A-Q]] ) { with

    my $currentChar = substr( $string, $n, 1 ); if( $currentChar eq 'C' ) { $currentChar = substr( $string, ++$n, 1 ); if( $currentChar eq '1' ) { $currentChar = substr( $string, ++$n, 1 ); if( $currentChar eq 'A' ) { ... ... ... ... elsif( $currentChar eq 'B' ... ... ... ... } elsif( $currentChar eq '2' ) { ... ... ... ... } elsif( $currentChar eq '3' ) { ... ... ... ... } elsif( $currentChar eq '4' ) { ... ... ... ... } elsif( $currentChar eq '5' ) { ... ... ... ... } elsif( $currentChar eq '6' ) { ... ... ... ... } elsif( $currentChar eq '7' ) { ... ... ... ... } elsif( $currentChar eq '8' ) { ... ... ... ... } elsif( $currentChar eq '9' ) { ... ... ... ... } else { die "The second char was not in range '1' thru '9'; } } else { die "The first character didn't match 'C'"; }

    Because that is the logical equivalent of your advice!

    Or might you suggest working around the problem, and report the error, in the hope that the regex engine would get fixed?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Because that is the logical equivalent of your advice!

      No. A construed analogy is not a logical equivalent.

      My advice is to go with the framework, and try to use features of the framework rather than bending it, or mix in stuff which might lead to problems.

      It just so happens that Tk can be used together with threads, but it wasn't written using threads - has it even been designed with threads in mind?

      The OP was about a Tk problem, so I have posted a solution which works making use of Tk and its features. It was not me who was reaching for something entirely different, but you!

      My solution might induce the wish to get a deeper understanding of how Tk works, and how to use it's lesser known internals directly - your solution of using threads just avoids a black spot which isn't in the toolkit, but in the knowledge of its user, and places on him the intellectual weight of understanding how's that thread stuff works and how to avoid pitfalls combining both... I remember you wrote something along that lines in a fine post elsewhere... ;-)

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://668765]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-26 05:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found