in reply to XS module in ithreads Perl much slower in threads::join after adding SvOBJECT_off

It just dawned on me. Shouldn't destroy (or any re-assignment) happen in the thread and/or process that the the object was created in? i.e. $$.$tid

Basically, to not DESTROY the object unless the owner ($$.$tid) which instantiated the object.

  • Comment on Re: XS module in ithreads Perl much slower in threads::join after adding SvOBJECT_off

Replies are listed 'Best First'.
Re^2: XS module in ithreads Perl much slower in threads::join after adding SvOBJECT_off
by Anonymous Monk on Feb 28, 2022 at 08:33 UTC
    Yes, basically vars arent shared by default, they live/die in their own threads.

    hows the memory usage affected by SvOBJECT_off?

    sounds like before SvOBJECT_off was added, the memory was being freed during global destruction , thus it was faster as a side effect... ??

    Why no strassen with plain threads module?

    all those my $a really niggle

      It's even possible this might be a documentation/application problem: the PDL object is getting destroyed, and I argue that anything other than the new behaviour only worked by coincidence. But the timing (and thread "location") of that destruction is in the hands of the wider application. Obviously, I'll be happy to add any needed Perl-threads support, protected by #ifdef, if someone can tell me what that would be :-)

      Are there any easy fixes for this, e.g. in the scripts being discussed here? Or does PDL::Parallel::threads need updating?

        Hi, etj

        There is awesomeness with PDL 2.076 in better utilization of the L1/L2/L3 cache. That is something to be proud of and a moment of celebration. Unfortunately, 2.076 introduces an anomaly. IMHO try storing the $$.$tid somewhere. For PDL to be thread-safety friendly, it is important for cleanup to occur by the originating thread which instantiated the object.

        I will update the MCE demonstrations with a user_begin block to work around the issue. This I can do safely, because the piddles are instantiated by the main thread; i.e. $$.tid == $$.0

        Update: Looking at the code, MCE workers also form piddles for the Strassen demonstrations. So I cannot do this unless I save/check the thread ID.

        user_begin => sub { # PDL 2.076 introduced a regression causing all threads to perform # piddle destruction. PDL cleanup should occur once, preferably by # the thread which instantiated the object. no warnings; sub PDL::DESTROY { 0; } },

        Not able to do the above, I want to mention that the strassen_07_t.pl example works fine as is in the repo by removing the line introduced in PDL 2.076.

        SvOBJECT_off((SV *)it->sv);