Article View: pl.comp.lang.perl
Article #51719Re: Thread::Queue a pusty hash na wyjsciu [share na hashu niszczy zawartość]
From: Szymon Sokół
Date: Wed, 23 Dec 2009 20:04
Date: Wed, 23 Dec 2009 20:04
52 lines
2379 bytes
2379 bytes
On Wed, 23 Dec 2009 19:49:33 +0100, Andrzej Adam Filip wrote:
> Krzysztof Lewicki <menth0l@remove.this.o2.pl> pisze:
[----]
> <quote src="man Threads::shared">
> BUGS AND LIMITATIONS
> When "share" is used on arrays, hashes, array refs or hash refs,
> any data they contain will be lost.
> </quote>
Ja bym w ogóle ten kod przerobił tak:
use threads;
use threads::shared;
use Thread::Queue;
my $queue = Thread::Queue->new();
my $t1 = threads->create(\&test_reader);
my $t2 = threads->create(\&test_writer);
$t1->join();
$t2->join();
sub test_writer
{
my %t;
my $rt = share(%t);
while(1)
{
sleep 1;
%t = (1 => 'A', 2 => 'B');
$queue->enqueue($rt);
}
}
sub test_reader
{
my %hash;
my $ref;
while($ref=$queue->dequeue())
{
%hash = %{$ref};
print %hash, "\n";
}
}
U mnie to działa, sprawdzone.
--
Szymon Sokół (SS316-RIPE) -- Network Manager B
Computer Center, AGH - University of Science and Technology, Cracow, Poland O
http://home.agh.edu.pl/szymon/ PGP key id: RSA: 0x2ABE016B, DSS: 0xF9289982 F
Free speech includes the right not to listen, if not interested -- Heinlein H
Technical Details
Message-ID:
<jxlpb2uioga0$.dlg@falcon.sloth.hell.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!news.onet.pl!agh.edu.pl!news.agh.edu.pl!dustpuppy.sloth.hell.pl!not-for-mailReferences:
<hgth64$21l6$1@news.mm.pl> <iqrpawesz7-9CN@cynthia.brudna.chmurka.net>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!news.onet.pl!agh.edu.pl!news.agh.edu.pl!dustpuppy.sloth.hell.pl!not-for-mail
From: Szymon Sokół
<szymon@bastard.operator.from.hell.pl>
Newsgroups: pl.comp.lang.perl
Subject: Re: Thread::Queue a pusty hash na wyjsciu [share na hashu niszczy
zawartość]
Date: Wed, 23 Dec 2009 21:04:25 +0100
Organization: Guy Fawkes Society
Lines: 52
Sender: szymon@news.agh.edu.pl
Message-ID: <jxlpb2uioga0$.dlg@falcon.sloth.hell.pl>
References: <hgth64$21l6$1@news.mm.pl> <iqrpawesz7-9CN@cynthia.brudna.chmurka.net>
NNTP-Posting-Host: chello089079192166.chello.pl
Mime-Version: 1.0
X-Trace: news.agh.edu.pl 1261598687 30312 89.79.192.166 (23 Dec 2009 20:04:47 GMT)
X-Complaints-To: abuse@agh.edu.pl
NNTP-Posting-Date: Wed, 23 Dec 2009 20:04:47 +0000 (UTC)
User-Agent: 40tude_Dialog/2.0.15.1 Hamster/2.1.0.11
X-Face: xic?6f"rD)k-tM.]L]A6l4W7_aGt({}&{D,hiRI.8cPtf,1F.w@Qkl!vr23o1UY-BfXO$p< hk5>ijB?eBy)?!C<@)+%U\&`1X)MJ>.i.qgkY]4mvL62j<|xJRG/5:7:l8q]x;v!)Bz^r/!yG8DxoD -@fnC,g]BAXj
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit