They asked me this question — what’s the difference between mutex and semaphore during an interview

<p>It seems hard for my friend who is a self-taught developer.</p> <h1>Beginning</h1> <p>&ldquo;Last week they asked me what is multi-threading and if have I ever done anything with that, I answered the question&rdquo;. my friend said.</p> <p>&ldquo;Okay sounds good, hope you will pass it&rdquo;. I told him.</p> <p>&ldquo;But then he asked me how to make sure resources safely be accessed in multi-threading situations&rdquo;. he said.</p> <p>&ldquo;You should know lock right?&rdquo; I told him.</p> <p>&ldquo;Yes I answered him lock but then he asked what is semaphore and what is the difference I have no idea what is semaphore so I told the interviewer I don&rsquo;t know could you tell me what is that ?&rdquo;. he said.</p> <p>&ldquo;then did he tell you the answer?&rdquo; I asked.</p> <p>&ldquo;Yes, he said semaphore is a signal mechanism which is used for thread synchronization; and the purpose of a mutex is to protect resource access from other threads while only allowing one thread to use it,&rdquo; he said.</p> <p>&ldquo;So you got it?&rdquo; I asked.</p> <p>&ldquo;No&hellip;can you explain to me how it works under the hood without too many CS terms?&rdquo; he asked.</p> <p><a href="https://iorilan.medium.com/they-asked-me-this-question-whats-the-difference-between-mutex-and-semaphore-during-an-interview-d862bb053f86">Read More</a></p>