zoukankan      html  css  js  c++  java
  • 多线程中的变量共享

     1 use threads;
     2 use threads::shared;
     3 my $count:shared = 1;
     4 print "主线程中count为:$count
    ";
     5 
     6 sub thread1{
     7         print "线程1增加1
    ";
     8         $count++;
     9         print "在线程1中结果为:$count
    ";
    10         sleep(1);
    11 }
    12 sub thread2{
    13         print "线程2增加1
    ";
    14         $count++;
    15         print "在线程2中结果为:$count
    ";
    16         sleep(1);
    17 }
    18 
    19 my $th1 = threads->new('thread1');
    20 my $th2 = threads->new('thread2');
    21 $th1->join();
    22 $th2->join();
    23 print "当所有线程结束时count的值为:$count
    "
  • 相关阅读:
    软件测试
    软件测试
    软件测试
    软件测试
    软件测试
    软件测试
    软件测试
    软件测试
    软件测试
    When:什么时候做集成测试
  • 原文地址:https://www.cnblogs.com/perl6/p/6462155.html
Copyright © 2011-2022 走看看