Fix race between the queue monitor and the builder threads

Created by  Eelco Dolstra  on June 18, 2015
HUUZFPPKGHTXFZMZCO2UGWYNGEED3E2CFHQRFQVVBJGPQVGVY4UAC
Change contents