implementing locking rather than thread confinement