fix a race in im_maxpos_avg()