unit test for Semaphore

fixed failed test

cleaned code
unit test for more cases
cleaned code and added TestThread into support class
Merge pull request #3239 from hasancelik/feature/master/unitTestForSemaphore

unit test for Semaphore