Code Monkey home page Code Monkey logo

Comments (6)

jcupitt avatar jcupitt commented on June 15, 2024 1

Hi @akash-akya,

Oh dear, that's bad, I'll have a look. Thank you for the detailed report.

from libvips.

jcupitt avatar jcupitt commented on June 15, 2024

I made a tiny C prog to reproduce this:

/* Stress-test libvips fft.
 *
 * Compile with:
 *
 *  gcc -g -Wall soak8.c `pkg-config vips --cflags --libs`
 *
 * Run with:
 *
 *  ./a.out ~/pics/k2.jpg 
 */

#include <unistd.h>
#include <vips/vips.h>

/* How many ffts we run at once.
 */
#define NUM_IN_PARALLEL (32)

/* Number of ffts we do in total.
 */
#define TOTAL_OPERATIONS (NUM_IN_PARALLEL * 2000)

static GThreadPool *pool = NULL;

/* What we run as a thread.
 */
static void
worker( void *data, void *user_data )
{
    const char *file = (const char *) data;

    VipsImage *im, *x;

    if( !(im = vips_image_new_from_file( file, NULL )) )
        vips_error_exit( NULL );

    if( vips_crop( im, &x, 0, 0, 512, 512, NULL ) )
        vips_error_exit( NULL );
    g_object_unref( im );
    im = x;

    if( vips_fwfft( im, &x, 0.1, NULL ) )
        vips_error_exit( NULL );
    g_object_unref( im );
    im = x;

    if( !(x = vips_image_copy_memory( im )) )
        vips_error_exit( NULL );

    g_object_unref( im );
    g_object_unref( x );
}

int
main( int argc, char **argv )
{
    int i;

    if( VIPS_INIT( argv[0] ) )
        return( -1 );

    pool = g_thread_pool_new( worker, NULL, NUM_IN_PARALLEL, FALSE, NULL );

    for( i = 0; i < TOTAL_OPERATIONS; i++ )
        g_thread_pool_push( pool, argv[1], NULL );

    /* Wait for all threads to finish.
     */
    g_thread_pool_free( pool, FALSE, TRUE );

    sleep( 1 );

    return( 0 );
}

And it crashes every time with a double free error. valgrind seems to pass, annoyingly.

from libvips.

akash-akya avatar akash-akya commented on June 15, 2024

That's quick. I'll reuse your snippet when I hit something similar next time!

Based on libfwfft thread safety docs, planer call must thread safe, right?

from libvips.

jcupitt avatar jcupitt commented on June 15, 2024

Yes, it probably just needs a few more locks.

from libvips.

jcupitt avatar jcupitt commented on June 15, 2024

OK, fixed in 8.15.1 and credited to you. Thanks again!

from libvips.

akash-akya avatar akash-akya commented on June 15, 2024

@jcupitt Thanks! You don't really have to.
I am a lurker of this repo and I learned so much from your answers, comments and code in this repo and Stack Overflow. You answer every simple question with so much patience! Thank you for that :)

from libvips.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.