Subject: | not thread-safe |
As discussed via email a test case:
$ $ uname -a
Linux <some hostname> 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
(aka Ubuntu 14)
$ perl --version
This is perl 5, version 18, subversion 2 (v5.18.2) built for x86_64-linux-gnu-thread-multi
Geo::Calc version 0.12
Geo::Calc::XS version 0.27
##
## threads work
##
perl -e'use threads; use Geo::Calc::XS; $sub1 = sub { sleep rand(5); print "hello $_\n" }; for(1..10){threads->create($sub1, $_)}; for (threads->list){$_->join}'
hello 5
hello 3
hello 7
hello 9
hello 2
hello 6
hello 10
hello 4
hello 8
hello 1
##
## works with Geo::Calc
##
perl -e'use threads; use Geo::Calc; $sub1 = sub { print Geo::Calc->new(lat=>rand(10),lon=>rand(10))->distance_to({lat=>rand(10),lon=>rand(10)}) . "\n"}; for(1..10){threads->create($sub1, $_)}; for (threads->list) { $_->join}'
212138.030398
779363.937456
823694.464644
653980.748643
609628.644446
456814.219506
561549.613325
1013771.146627
844519.088117
671392.88472
##
## works without threads
##
perl -e'use Geo::Calc::XS; $sub1 = sub { print Geo::Calc::XS->new(lat=>rand(10),lon=>rand(10))->distance_to({lat=>rand(10),lon=>rand(10)}) . "\n"}; for(1..10){$sub1->($_)}'742959.404265
659889.833937
482712.186619
157267.090277
290750.99762
1077439.748947
198570.958689
435368.018728
930930.730854
648655.579625
##
## fails
##
perl -e'use threads; use Geo::Calc::XS; $sub1 = sub { print Geo::Calc::XS->new(lat=>rand(10),lon=>rand(10))->distance_to({lat=>rand(10),lon=>rand(10)}) . "\n"}; for(1..10){threads->create($sub1, $_)}; for (threads->list) { $_->join}'
Segmentation fault (core dumped)