Allowing callers to specify how the semaphore is created and stopped, instead of doing so via boolean flags like it is done currently. This method doesn't scale, so use a factory instead. (cherry picked from commit 5a3fd69374)
5a3fd69374