modified limited semaphore implementation to allow callback functions to return value