Perl 板


LINE

其实我是完完全全的新手 底下只要看的到的程式都是改编自版主的XD (版主歹是 喔 囧) 话说我想要做的是这样 Server提供一个可写入的阵列(整数~size=10) Client可以读也可以写 但是一次只能有一个写入~读取可以有多个 其实我也不知道我在写啥XD 但是东拼西凑出来的东西如下 但是似乎就是没有办法去确认Server是不是正确的读取了Client的东西 还是只是client print自己的array :( #!/usr/bin/perl #Server use threads; use IO::Socket; my $server = IO::Socket::INET->new( LocalPort => 8088, Type => SOCK_STREAM, Listen => 32, Reuse =>1 ); my @array = (); while(my $client = $server->accept() ) { threads->create( "client_handler", $client); } sub client_handler { my $client = shift; while(<$client>) { push( @array, $_ ); } print $client foreach( @array ); $client->shutdown(1); $client->close(); } #!/usr/bin/perl #Client use IO::Socket; my $client = IO::Socket::INET->new( PeerAddr => "127.0.0.1", PeerPort => 8088); my @array = (); my $element = 0; while( $element != 10 ){ for ( 1 .. 10 ) { push( @array, $element ); } $element++; } print "$_\n" foreach( @array ); print $client foreach( @array ); while(<$client>) { print;} $client->close(); 因为完全不会写程式 所以这段话有点不懂 Each read/write thread should perform a busy loop incrementing a local variable from 0 to 2,000,000 before actually doing the reading or the writing of the shared array. Make sure that you put this loop inside the critical section of the thread. This simulates longer service and will therefore introduce more contention for the resource. busy loop 是啥米?? 好像是很重要的一段话 但是怎麽也看不懂:( 要储存离开又不自觉的按下esc 然後 : 然後 wq! 了 那ㄟ安ㄋㄟ?! -- --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 211.72.195.107
1F:推 LiloHuang:busy loop就是那个回圈会一直跑 每次跑得过程不间隔 04/13 19:46
2F:推 LiloHuang:这样会造成那个thread耗用cpu 100% 你可能要做sleep动作 04/13 19:46
3F:推 LiloHuang:不过原本read/write其实是block-I/O 所以你不用管他 04/13 19:47
4F:推 LiloHuang:理论上你资料有送过去 不过目前我还没时间帮你跑一下 04/13 19:48
5F:推 LiloHuang:等其他板友看看呗^^ 要不然就等明天我比较有空哩 04/13 19:48
6F:推 LiloHuang:另外他是在讲threads要做临界区间的保护避免资源竞争 04/13 19:49
7F:推 LiloHuang:你应该把 my @array = (); 改 my @array : shared = (); 04/13 19:51
8F:推 LiloHuang:这样基本上这个阵列就可以同时多个client thread存取了 04/13 19:51
9F:推 LiloHuang:记得 use threads::shared; 这样才可以使用喔 :) 04/13 19:52
10F:→ tonini:谢版主隆恩~~~~ ^_^ 04/13 19:59







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Boy-Girl站内搜寻

TOP