The "key" is the connection properties, the array elements are byte counts and states and such.
Below is the minimal code for the errors. Subroutine createContract() is called once as a simple subroutine, and then started as a thread.
As is; the listed errors result.
If ':shared' is removed from %Contract, and '&share' is removed from the assignment within the sub, the code works fine (as expected).
?? So, what is the proper form for sharing a hash of arrays between threads
?? Simpler yet, how to read back what is stored, regardless of threads
Line # 28 is the printf(.....) line.#!/usr/bin/perl -w use threads; use threads::shared; use Carp; my %Contracts :shared; # hash holding allowed connections my $key; &createContract; my $monitor_thr = threads->create( \&createContract ); my $res1 = $monitor_thr->join(); #==================================================================== sub createContract { $key = "123456789"; # If you want to share a newly created reference unfortunately # you need to use "&share([])" and "&share({})" syntax due to # problems with Perl's prototyping. # man page $Contracts{$key} = &share([100,200,300,400]); printf (" %s %u^%u^%u^%u^\n", $key, $Contracts{$key}[0], $Contracts{$key}[1], $Contracts{$key}[2], $Contracts{$key}[3], ); } ----------------------- # [oldcode]# perl minThreadHash # printf (...) interpreted as function at minThreadHash line 28. # Use of uninitialized value in printf at minThreadHash line 28. # Use of uninitialized value in printf at minThreadHash line 28. # Use of uninitialized value in printf at minThreadHash line 28. # Use of uninitialized value in printf at minThreadHash line 28. # 123456789 0^0^0^0^ # Use of uninitialized value in printf at minThreadHash line 28. # Use of uninitialized value in printf at minThreadHash line 28. # Use of uninitialized value in printf at minThreadHash line 28. # Use of uninitialized value in printf at minThreadHash line 28. # 123456789 0^0^0^0^
In reply to Shared Hash-of-Arrays between threads? by Wiggins
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |