A simpler, non-locking mechanism would be:
In reply to Re: avoiding a race by BrowserUk in thread avoiding a race by westy032001