Created
November 20, 2023 08:59
-
-
Save fpl/2eb2bbd13999e52f9e9ce228c45c117a to your computer and use it in GitHub Desktop.
Test script for https://github.com/ajolma/Geo-GDAL-FFI/issues/58
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use v5.18; | |
use threads; | |
use warnings; | |
use strict; | |
use Thread::Queue; | |
use Geo::GDAL::FFI; | |
my $q = Thread::Queue->new(); | |
my @in_thrds = (); | |
my @out_thrds = (); | |
my $nt = 5; | |
for my $i (1..$nt) { | |
my $t = threads->create( | |
sub { | |
while (my $h = $q->dequeue()) { | |
say "thread out$i: popped $h->{value}"; | |
} | |
} | |
); | |
push @out_thrds, $t; | |
} | |
for my $i (1..$nt) { | |
my $t = threads->create( | |
sub { | |
my $v = rand(100); | |
say "thread in$i: pushed $v"; | |
$q->enqueue({ value => $v }); | |
} | |
); | |
push @in_thrds, $t; | |
} | |
# try different timing too... :-/ | |
sleep(5); | |
$q->end(); | |
for my $w (@in_thrds) { | |
$w->join(); | |
} | |
for my $w (@out_thrds) { | |
$w->join(); | |
} | |
exit(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment