Check for semaphore max value.

We want to check that we never release a semaphore more than we acquired
it.
Merge pull request #3 from antoinealb/master

Check for semaphore max value.