Expert answer:Explain how the compare-and-swap hardware synchronization mechanism works. Give an example of its use and show how the compare-and-swap can be use to implement a semaphore?