Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

possible race in vips_sink_*() progress reporting #2820

Closed
jcupitt opened this issue May 23, 2022 · 1 comment
Closed

possible race in vips_sink_*() progress reporting #2820

jcupitt opened this issue May 23, 2022 · 1 comment
Labels

Comments

@jcupitt
Copy link
Member

jcupitt commented May 23, 2022

This program:

/* compile with
 *
 *      gcc -g -Wall race.c `pkg-config vips --cflags --libs`
 */

#include <vips/vips.h>

static void
posteval_cb( VipsImage *image, VipsProgress *progress, void *client )
{
        printf( "posteval_cb: percent = %d\n",
                progress->percent );
}

int
main( int argc, char **argv )
{       
        double avg;
        VipsImage *image;

        VIPS_INIT( argv[0] );
        
        vips_xyz( &image, 10, 1000, NULL );
        
        vips_image_set_progress( image, TRUE );
        g_signal_connect( image, "posteval", G_CALLBACK( posteval_cb ), NULL );
        
        printf( "testing vips_sink()\n" );
        vips_avg( image, &avg, NULL );
        printf( "sum = %ld\n",  
                (gint64) (avg * image->Xsize * image->Ysize * image->Bands) );

        printf( "testing vips_sink_memory()\n" );
        VipsImage *mem;
        mem = vips_image_copy_memory( image );
        VIPS_UNREF( mem );

        printf( "testing vips_sink_file()\n" );
        vips_image_write_to_file( image, "x.v", NULL );

        VIPS_UNREF( image );
        
        return( 0 );
}       

Sometimes won't print 100%:

$ ./a.out 
testing vips_sink()
posteval_cb: percent = 99
sum = 5040000
testing vips_sink_memory()
posteval_cb: percent = 99
testing vips_sink_file()
posteval_cb: percent = 99
$ ./a.out 
testing vips_sink()
posteval_cb: percent = 100
sum = 5040000
testing vips_sink_memory()
posteval_cb: percent = 99
testing vips_sink_file()
posteval_cb: percent = 100

Seems to affect all sinks, seems to only affect progress reporting (not the result of processing).

@jcupitt jcupitt added the bug label May 23, 2022
jcupitt added a commit that referenced this issue May 23, 2022
Because signals can be delayed, progress isn't always 100% in posteval.
Lock it to 100%.

See #2820
@jcupitt
Copy link
Member Author

jcupitt commented May 23, 2022

After some digging, this is just because signal emission can be delayed under load. Fix by just locking progress to 100% before triggering posteval.

@jcupitt jcupitt closed this as completed May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant