Check for semaphore max value.

We want to check that we never release a semaphore more than we acquired
it.