This function first posts a notice to all threads that it is time
to stop. It then waits until all threads actually *have* stopped,
and then then returns a lock object. All other threads will be
blocked from running until that object has been freed/destroyed.
It's mainly useful to do things that require a temporary uid/gid
change, since on many OS the effective user and group applies to
all threads.