Semaphore vs mutex: who can unlock?

Thread T1 calls sem_wait() on a counting semaphore (decrementing it) and starts some work. Thread T2, which never called sem_wait(), then calls sem_post() on that same semaphore. Compare this to a std::mutex: could T2 legally call unlock() on a mutex that T1 locked?

18 of 53 in Operating Systems