#12 Thread safety

POGL 0.xx
open
nobody
None
5
2014-12-17
2014-05-02
No

Hello!
Am I right in assuming OpenGL::Array is not thread safe? It looks like the underlying data storage is not duplicated when object is cloned, but DESTROY {} tries to free it twice.

The following workaround should be enough:
*OpenGL::Array::CLONE_SKIP = sub { 1 };

Discussion

  • Chris Marshall
    Chris Marshall
    2014-05-02

    I don't see a duplicate free() in the DESTROY() call for OpenGL::Array objects. This is for the current release version 0.6703. It is possible that the code is not thread safe but I don't think there are tests for that. Could you give a link/line number or more detail for what you see?

    Thanks,
    Chris

     
  • Oh, it's very easy to reproduce:

    my $array = OpenGL::Array->new(4, GL_FLOAT);
    threads->create(sub { $array })->join;

    perl(65121,0x313540) malloc: error for object 0x544540: pointer being freed was not allocated
    set a breakpoint in malloc_error_break to debug

    Double free() happens because both threads call $array->DESTROY().
    See http://perldoc.perl.org/perlmod.html#Making-your-module-threadsafe
    I think a CLONE_SKIP { 1 } would be the best choice for OpenGL::Array.

     
    • Chris Marshall
      Chris Marshall
      2014-05-03

      Thanks, I see what you mean. It is definitely not
      thread safe then. I'll add that work around and info
      to the release.

      -chm

      On Sat, May 3, 2014 at 5:17 AM, Alessandro Ranellucci
      alexrj@users.sf.netwrote:

      Oh, it's very easy to reproduce:

      my $array = OpenGL::Array->new(4, GL_FLOAT);
      threads->create(sub { $array })->join;

      perl(65121,0x313540) malloc:
      * error for object 0x544540: pointer being freed was not allocated * set
      a breakpoint in malloc_error_break to debug

      Double free() happens because both threads call $array->DESTROY().
      See http://perldoc.perl.org/perlmod.html#Making-your-module-threadsafe
      I think a CLONE_SKIP { 1 } would be the best choice for OpenGL::Array.


      Status: open
      Group: POGL 0.xx
      Created: Fri May 02, 2014 11:12 AM UTC by Alessandro Ranellucci
      Last Updated: Fri May 02, 2014 09:59 PM UTC
      Owner: nobody

      Hello!
      Am I right in assuming OpenGL::Array is not thread safe? It looks like the
      underlying data storage is not duplicated when object is cloned, but
      DESTROY {} tries to free it twice.

      The following workaround should be enough:
      *OpenGL::Array::CLONE_SKIP = sub { 1 };


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/pogl/bugs/12/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       
  • Hello Chris, any update on this?
    Thank you!

     
    • Chris Marshall
      Chris Marshall
      2014-12-17

      Where does the fix line go? Patches against git welcome.

       
  • Chris Marshall
    Chris Marshall
    2014-12-17

    It looks like this has already been applied to git master.
    Could you please verify that everything builds, runs, and
    looks ok and I'll push a new CPAN release as soon as I get
    confirmation from you.

    Thanks,
    Chris