Added functional tests, fixed bug in rw_semaphore