in reply to Multi-thread friendly object life-time handling for XS modules
With the unblessed object:use warnings; use strict; use threads; use Math::MPFR qw(:mpfr); my ($x, $inex) = Rmpfr_init_set_d(11.625, MPFR_RNDN); my $thr1 = threads->create( sub { print Rmpfr_get_d($x, MPFR_RNDN), "\n"; return 23; } ); ## Line 12 my $res = $thr1->join(); print $res; __END__ OUTPUTS: 11.625 Free to wrong pool 4ab7e0 not 49aee0 at threads.pl line 12.
Maybe that's an overly simplistic and/or irrelevant demo. (My knowledge of threads is very week.)use warnings; use strict; use threads; use Math::MPFR qw(:mpfr); my ($x, $inex) = Rmpfr_init_set_d_nobless(11.625, MPFR_RNDN); my $thr1 = threads->create( sub { print Rmpfr_get_d($x, MPFR_RNDN), "\n"; return 23; } ); my $res = $thr1->join(); Math::MPFR::DESTROY($x); print $res; __END__ OUTPUTS: 11.625 23
|
|---|