Hi David!

On 08 июл 12 at 04:59, "David" (David Mertens) wrote:

Hi all,

Long time ago I tried to play with threads and Prima, but failed very
quickly. The problem I hit was that calling Prima methods from a scalar,
i.e. as simple as $window->some_method() from a different thread
goes bad, because $window in thread1 and $window in thread2 are
different memory structures, whereas some_method() which is written
in C assumes that they aren't.  This is a base perl feature - each
thread runs in its own interpreter. It can be somewhat I think worked
around with help of threads::shared, but I didn't try that, for another
reason.

Prima by design is not thread-safe because there are so many global
state variables, and even if it would be possible to circumvent the problem
above, it requires a huge effort to go through all code to make sure it
is thread safe. Subjectively, I don't justify that effort, because it looks
to me that people mostly call GUI from other threads to reflect state of
a lenghty calculation or a similar, and that can be done by some other
IPC method, where thread2 signals a condition and thread1 picks it up
and calls a Prima method. 

Well anyway I'm willing to cooperate if there are volunteers that want
to try this risky enterprise, but personally I don't see much interest or
benefit in this.

/dk

 David>    On Sat, Jul 7, 2012 at 5:50 AM, zentara <[email protected]> 
wrote:
 David>      On Fri, 06 Jul 2012 18:44:01 +0200

 David>    Fabio D'Alfonso <[email protected]> wrote:

   >Hi,
 >> below it is a copy of a comment I made after David Mertens commented
 David>    on
 >> one of my posts on Prima.

 >> Any comment to this is welcome.
 >> 

     Hi,
 David>      I'm interested in different GUI toolkits, and just started
 David> looking at Prima.  My one question is this: Is Prima threadsafe? Or
 David> are there methods to use so that a programmer can access a Prima
 David> widget from a thread?

 David>    Prima is not thread safe. I have pondered addressing this issue
 David> and I suspect that if you looked into the matter and offered a
 David> (cross-platform) patch to Prima that would allow it to be Perl
 David> thread-safe, Dmitry would be delighted. Don't take my word for
 David> it---I'm not Dmitry---but it's the rare open source developer who
 David> would reject such a useful and nontrivial patch.

 David>      Tk is known to be NOT threadsafe, with a bunch of well known
 David> hacks for dealing with the problem.  Gtk2 has improved thread
 David> safety, and you can safely access a Gtk2 widget from a thread with
 David> an Glib::Idle->add().  How does Prima fit into this, because it
 David> would seem that using it with PDL would often need the PDL routines
 David> running in a thread, so as not to interfere with the GUI
 David> event-loop.

 David>    Yes... well... I have actually written PDL::PP code with
 David> optional callbacks so that I could update the GUI interface of my
 David> program during lengthy calculations. Such a callback interface is
 David> useful for any sort of lengthy PDL operation (even if only for
 David> printing status updates to the terminal) but they are not
 David> implemented in any of our routines. This is one of the sorts of
 David> things that I intend to cover if I ever get to writing a second
 David> chapter on PDL::PP for PDL::Book.  So to answer your question,
 David> threadsafe Prima would make all of this much easier, but it's not
 David> strictly required to maintain a responsive user interface.

 David>      Thanks for reading this.  0m, zentara

 David>    You're welcome. :-) David

 David>    -- "Debugging is twice as hard as writing the code in the first
 David> place.  Therefore, if you write the code as cleverly as possible,
 David> you are, by definition, not smart enough to debug it." -- Brian
 David> Kernighan

-- 
Sincerely,
        Dmitry Karasik


_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to