🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: be.comp.programming
Article #1965

Threads en shared variabele

#1965
From: Nitro
Date: Tue, 09 Nov 2004 23:06
39 lines
2068 bytes
ik heb een aantal threads, en ik wil dat die allemaal dezelfde hashmap
gebruiken. Dit gaat met shared. 

Nu wil ik echter in die hashmap handles van netwerkverbindingen steken.
Hier gaat het mis: "thread failed to start: Can't upgrade that kind of
scalar at ./test.pl line 19." is het resultaat.

Laat ik die shared weg werkt het, maar heb ik geen gesharede hashmap.


Iemand een suggestie

Nitro


PS Niet letten op "onchristelijkheden", dit is maar rap in elkaar geflanst.



#!/usr/bin/perl

use warnings;
use strict;
use Socket;
use threads;
use threads::shared;

my %hash : shared;
socket(my $socket, PF_INET, SOCK_STREAM, getprotobyname('tcp')) or die "Error creating TCP-socket\n";
bind($socket, sockaddr_in(1863, INADDR_ANY)) or die "Error binding to port 1863\n";
listen($socket, 10) or die "Cannot listen at defined socket\n";
accept(my $client, $socket);
threads->new( sub { test($client)});

sub test{
my($conn) = @_;
$hash{"client"} = $conn;
print("$hash{'client'}\n");
}
Technical Details
Message-ID: <pan.2004.11.09.23.06.41.760419@skynet.be>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeeder.wxs.nl!aotearoa.belnet.be!ikaria.belnet.be!news.belnet.be!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: fcea4,36e8d92838c02512,start
X-Google-Attributes: gidfcea4,public
X-Google-Language: DUTCH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeeder.wxs.nl!aotearoa.belnet.be!ikaria.belnet.be!news.belnet.be!not-for-mail
From: Nitro <nitroglycerine@skynet.be>
Newsgroups: be.comp.programming
Subject: Threads en shared variabele
Date: Wed, 10 Nov 2004 00:06:43 +0100
Organization: KULeuvenNet
Lines: 39
Message-ID: <pan.2004.11.09.23.06.41.760419@skynet.be>
NNTP-Posting-Host: seven.kulnet.kuleuven.ac.be
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: ikaria.belnet.be 1100041599 10843 134.58.127.12 (9 Nov 2004 23:06:39 GMT)
X-Complaints-To: abuse@belnet.be
NNTP-Posting-Date: Tue, 9 Nov 2004 23:06:39 +0000 (UTC)
User-Agent: Pan/0.14.2.91 (As She Crawled Across the Table (Debian GNU/Linux))
Cache-Post-Path: seven.kulnet.kuleuven.ac.be!unknown@bluebird.kotnet.org
X-Cache: nntpcache 2.4.0b5 (see http://www.nntpcache.org/)