logo       

Re: Threads: msg#00011

Subject: Re: Threads
Hi,

I think 2 - cloning the C++ objects is probably just about the best
option. I can imagine the possibility of a situation where it might be
of some use for a thread to get a copy of a parent object and go to work
on that in the background.

Having said that, I would not choose 2 if that option represented much
more work than 1 or 3.

As there's no clear obvious choice, I think whichever option is easiest
for you to implement.

I assume we are only concerned with the listed object types and that
with any of the options, the following code in a secondary thread would
still work (I'm concerned about using Wx::Window::FindWindowById in the
context shown below)

my $WINDOW_ID = (the ID of a window in my main gui thread);
my $window = Wx::Window::FindWindowById($WINDOW_ID, undef);
my $newevent = Wx::PlThreadEvent->new( -1, $MY_EVENT_ID, $sharedvar );
Wx::PostEvent( $window, $newevent );

Regards

Mark


Mattia Barbon wrote:
>   Hi all,
> the topic is abviously threads. This program:
> 
> ==========
> #!/usr/bin/perl -w
> 
> use strict;
> use warnings;
> use threads;
> use Test::More tests => 4;
> 
> use Wx;
> 
> my $app = Wx::App->new( sub { 1 } );
> my $color = Wx::Colour->new( 0, 10, 20 );
> 
> use Devel::Peek;
> 
> my $t = threads->create
>   ( sub {
>         ok( 1, 'In thread' );
>     } );
> ok( 1, 'Before join' );
> $t->join;
> ok( 1, 'After join' );
> 
> END { ok( 1, 'At END' ) };
> =========
> 
> crashes after test 3 (after join). The reason is that when the thread is
> started the perl-space variables are cloned, but the C++-space objects
> are not, so bot threads think they hold the last reference to $color,
> both try to free the underlying C++ object => segmentation fault.
> 
>   There are various way to work around this; all involve keeping tracks
> of created objects (Wx::Colour instances in this case) and doing something
> special at clone time. This solves the problem once you decide what
> special action you want to take.
> 
>   Options:
> 1 - the new thread is denied access to the parent thread objects
>     (tried and works; you should not access wxThings from multiple
>      threads anyway)
> 2 - clone the C++ instances; for each variable do (more or less)
>     $var = Wx::Colour->new( $var );
> 3 - give the new thread access to the original thread's C++ objects
>     avoiding the double free (i.e. do what happens now, except for the
>     segfault).
> 4 - other options?
> 
>   Any suggestions?
> 
> Thanks!
> Mattia
> 
>   The list of classes needing special treatment is:
> Wx::DataObject
> Wx::DropTarget
> Wx::FileSystem
> Wx::FSFile
> Wx::GridCellAttr
> Wx::GridCellAttr
> Wx::GridCellEditor
> Wx::GridCellRenderer
> Wx::HtmlEasyPrinting
> Wx::Printer
> Wx::XmlResource
> Wx::Accelerators
> Wx::Bitmap
> Wx::Brush
> Wx::Cursor
> Wx::Font
> Wx::Icon
> Wx::Image
> Wx::ImageList
> Wx::Locale
> Wx::Palette
> Wx::Pen
> 
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys -- and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> wxperl-users mailing list
> wxperl-users@xxxxxxxxxxxxxxxxxxxxx
> https://lists.sourceforge.net/lists/listinfo/wxperl-users



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
web.pylons.gene...    hurd.l4/2002-10...    kernel.commits....    user-groups.lin...    yellowdog.gener...    java.drools.use...    security.openva...    package-managem...    linux.debian.us...    qnx.openqnx.dev...    genealogy.gramp...    file-systems.if...    voip.wengophone...    tex.context/200...    ietf.smime/2003...    audio.csound.de...    culture.region....    xfree86.devel/2...    mobile.kannel.u...    distributed.con...    education.engli...    org.user-groups...    bug-tracking.gn...    recreation.bicy...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe