🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.perl
Article #51714

Thread::Queue a pusty hash na wyjsciu

#51714
From: Krzysztof Lewicki
Date: Wed, 23 Dec 2009 16:40
41 lines
1731 bytes
Potrzebuje użyć wątków perlowych i natrafiłem na pewien problem. Napisałem 
sobie taki oto przykładowy fragment kodu:

my $queue = Thread::Queue->new();
my $t1 = threads->create(\&test_reader);
my $t2 = threads->create(\&test_writer);

$t2->join();

sub test_writer
{
	while (1)
	{
		sleep 1;
		my %t = (1 => "A", 2 => "B")
		$queue->enqueue(share(%t));
	}	
}

sub test_reader
{
	threads->detach();
	
	while (my $ref= $queue->dequeue())
	{
		my %hash = %{$ref}; # wyswietla np. HASH(0x1110970)
		print %hash; # tu juz nic nie wyswietla
	}
}

Jedna kolejka, 2 watki, jeden czyta z kolejki, drugi zapisuje. Niby 
proste. Problem pojawia sie jednak w funkcji test_reader. Otóż podczas 
wyciagania z kolejki dostaje referencje na hash (print $ref daje cos w 
stylu HASH(0x1110970)) i dotad - chyba - jest OK. Kiedy probuje wyciagnac 
hasha z referencji dostaję... pustkę.

Nie wiem co z tym fantem zrobic, moze ktos mnie naprowadzi?

-- 
Pozdrawiam,
menth0l
Technical Details
Message-ID: <hgth64$21l6$1@news.mm.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!news.task.gda.pl!news.mm.pl!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!news.task.gda.pl!news.mm.pl!not-for-mail
From: Krzysztof Lewicki <menth0l@remove.this.o2.pl>
Newsgroups: pl.comp.lang.perl
Subject: Thread::Queue a pusty hash na wyjsciu
Date: Wed, 23 Dec 2009 16:40:36 +0000 (UTC)
Organization: Multimedia Polska SA
Lines: 41
Message-ID: <hgth64$21l6$1@news.mm.pl>
NNTP-Posting-Host: host-89-230-212-184.lublin.mm.pl
Mime-Version: 1.0
X-Trace: news.mm.pl 1261586436 67238 89.230.212.184 (23 Dec 2009 16:40:36 GMT)
X-Complaints-To: abuse@multimedia.pl
NNTP-Posting-Date: Wed, 23 Dec 2009 16:40:36 +0000 (UTC)
User-Agent: Pan/0.133 (House of Butterflies)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit