'Do the given work on this thread, with the mutex acquired.  If this is
called re-entrantly, return and wait for the outer invocation to do the
work.
@param work: the work to do with the lock held.'

def do(self, work):

    lock = self._lock
    local = self._local
    self._quit.check()
    working = getattr(local, 'working', None)
    if (working is None):
        working = local.working = []
        working.append(work)
        lock.acquire()
        try:
            while working:
                working.pop(0)()
        finally:
            lock.release()
            local.working = None
    else:
        working.append(work)
