| |||
Semaphore/Mutex interview question
So I had a phone interivew for an embedded software position with a major communications company and was asked some questions that I didn't seem to answer to the interviewer's satisfaction. enough, I got called back for an on-site interview. Anyways, I want to run these questions by others to see what the real answer is. 1) What is the difference between a mutex and a binary semaphore? I couldn't really think of a difference but he seemed to be leading me to an answer. He asked if you can use a mutex in an interrupt service routine and then asked if you could use a semaphore within an interrupt service routine. of the questions he asked during the interview was whether I had heard the term "munching". Well, after the interview I looked it up and it is some term specific to VxWorks. Not having worked with VxWorks before I decided to read a VxWorks manual online. It seems like almost all his questions were related to VxWorks even though he didn't say so. Is there really one "correct" answer to the mutex vs binary sempahore question? There definitely does seem to be a difference in VxWorks as mutexes handle priority inversion. It seems to be S / library dependent and thus seems a bit unfair, but correct me if I'm wrong. Thanks.
|
#
2
| |||
| |||
Semaphore/Mutex interview question
Fri, 15 Sep 2006 05:49:51 +0200 schreef joshc <josh.curtz@gmail.com>: So I had a phone interivew for an embedded software position with a major communications company and was asked some questions that I didn't seem to answer to the interviewer's satisfaction. enough, I got called back for an on-site interview. Anyways, I want to run these questions by others to see what the real answer is.
> 1) What is the difference between a mutex and a binary semaphore? I guess it is valid to say that because these clumsy primitives are error prone and cause unwanted effects, the answer to this question is irrelevant. But I guess that I am spoilt for knowing easier-to-understand and less ugly ways to make processes communicate. I couldn't really think of a difference but he seemed to be leading me to an answer. He asked if you can use a mutex in an interrupt service routine and then asked if you could use a semaphore within an interrupt service routine. of the questions he asked during the interview was whether I had heard the term "munching". Well, after the interview I looked it up and it is some term specific to VxWorks. Not having worked with VxWorks before I decided to read a VxWorks manual online. It seems like almost all his questions were related to VxWorks even though he didn't say so.
> Is there really one "correct" answer to the mutex vs binary sempahore question? There definitely does seem to be a difference in VxWorks as mutexes handle priority inversion. It seems to be S / library dependent and thus seems a bit unfair, but correct me if I'm wrong. The question indeed relies on the interpretations of these concepts by a specific implementor. -- Gemaakt met 's revolutionaire e-mailprogramma: http://www.opera.com/mail/
|
#
3
| |||
| |||
Semaphore/Mutex interview question
joshc wrote: So I had a phone interivew for an embedded software position with a major communications company and was asked some questions that I didn't seem to answer to the interviewer's satisfaction. enough, I got called back for an on-site interview. Anyways, I want to run these questions by others to see what the real answer is.
> 1) What is the difference between a mutex and a binary semaphore? The purpose differs. Expand the name MUTEX is MUTual EXclusion. You use it to prevent two or more processes from executing the same section of code at the same time. Whereas a semaphore is just a signalling mechanism. Why he would specifically use a binary semaphore in the questions if strange. I couldn't really think of a difference but he seemed to be leading me to an answer. He asked if you can use a mutex in an interrupt service routine and then asked if you could use a semaphore within an interrupt service routine. of the questions he asked during the interview was whether I had heard the term "munching". Well, after the interview I looked it up and it is some term specific to VxWorks. Not having worked with VxWorks before I decided to read a VxWorks manual online. It seems like almost all his questions were related to VxWorks even though he didn't say so.
> Is there really one "correct" answer to the mutex vs binary sempahore question? There definitely does seem to be a difference in VxWorks as mutexes handle priority inversion. It seems to be S / library dependent and thus seems a bit unfair, but correct me if I'm wrong.
> Thanks. hth, ed
|
#
4
| |||
| |||
Semaphore/Mutex interview question
Ed Prochak wrote: joshc wrote: So I had a phone interivew for an embedded software position with a major communications company and was asked some questions that I didn't seem to answer to the interviewer's satisfaction. enough, I got called back for an on-site interview. Anyways, I want to run these questions by others to see what the real answer is.
> 1) What is the difference between a mutex and a binary semaphore?
> The purpose differs. Expand the name MUTEX is MUTual EXclusion. You use it to prevent two or more processes from executing the same section of code at the same time. Whereas a semaphore is just a signalling mechanism. Why he would specifically use a binary semaphore in the questions if strange.
> hth, ed Yes, but a semaphore can be used for mutual exclusion too. The differences I found in VxWorks' implementation of mutexes and semaphores are very implementation specific. Any more ideas on common differences between mutexas and semaphores?
|
#
5
| |||
| |||
Semaphore/Mutex interview question
Maybe the difference is in how the waitng processes are woken up. Maybe relating to which process and structures are responsible for managing each. I would think that semaphores are individually managed by each owning process while mutexes are centralling managed. This difference may make a big difference with respect to how interrupts impact each. Probably not correct, but my 2 cents. Hicks "joshc" <josh.curtz@gmail.comwrote in message news:1158292191.257574.114150@ So I had a phone interivew for an embedded software position with a major communications company and was asked some questions that I didn't seem to answer to the interviewer's satisfaction. enough, I got called back for an on-site interview. Anyways, I want to run these questions by others to see what the real answer is.
> 1) What is the difference between a mutex and a binary semaphore? I couldn't really think of a difference but he seemed to be leading me to an answer. He asked if you can use a mutex in an interrupt service routine and then asked if you could use a semaphore within an interrupt service routine. of the questions he asked during the interview was whether I had heard the term "munching". Well, after the interview I looked it up and it is some term specific to VxWorks. Not having worked with VxWorks before I decided to read a VxWorks manual online. It seems like almost all his questions were related to VxWorks even though he didn't say so.
> Is there really one "correct" answer to the mutex vs binary sempahore question? There definitely does seem to be a difference in VxWorks as mutexes handle priority inversion. It seems to be S / library dependent and thus seems a bit unfair, but correct me if I'm wrong.
> Thanks.
>
|
#
6
| |||
| |||
Semaphore/Mutex interview question
joshc wrote: So I had a phone interivew for an embedded software position with a major communications company and was asked some questions that I didn't seem to answer to the interviewer's satisfaction. enough, I got called back for an on-site interview. Anyways, I want to run these questions by others to see what the real answer is.
> 1) What is the difference between a mutex and a binary semaphore? I couldn't really think of a difference but he seemed to be leading me to an answer. He asked if you can use a mutex in an interrupt service routine and then asked if you could use a semaphore within an interrupt service routine. of the questions he asked during the interview was whether I had heard the term "munching". Well, after the interview I looked it up and it is some term specific to VxWorks. Not having worked with VxWorks before I decided to read a VxWorks manual online. It seems like almost all his questions were related to VxWorks even though he didn't say so.
> Is there really one "correct" answer to the mutex vs binary sempahore question? There definitely does seem to be a difference in VxWorks as mutexes handle priority inversion. It seems to be S / library dependent and thus seems a bit unfair, but correct me if I'm wrong. A mutex is used to ensure that only a single "thread" accesses a resource. A (binary) semaphore is a mechanism that can be used to implement a mutex. Not all semaphores are mutex'es (just like not all counters are semaphores).
|
#
7
| |||
| |||
Semaphore/Mutex interview question
"joshc" <josh.curtz@gmail.comwrote in message news:1158292191.257574.114150@ So I had a phone interivew for an embedded software position with a major communications company and was asked some questions that I didn't seem to answer to the interviewer's satisfaction. enough, I got called back for an on-site interview. Anyways, I want to run these questions by others to see what the real answer is.
> 1) What is the difference between a mutex and a binary semaphore? I couldn't really think of a difference but he seemed to be leading me to an answer. He asked if you can use a mutex in an interrupt service routine and then asked if you could use a semaphore within an interrupt service routine. of the questions he asked during the interview was whether I had heard the term "munching". Well, after the interview I looked it up and it is some term specific to VxWorks. Not having worked with VxWorks before I decided to read a VxWorks manual online. It seems like almost all his questions were related to VxWorks even though he didn't say so In VxWorks perspective, a mutex is roughly a semaphore with an initial value of 1. (With a few restrictions and variations). Steve
> Is there really one "correct" answer to the mutex vs binary sempahore question? There definitely does seem to be a difference in VxWorks as mutexes handle priority inversion. It seems to be S / library dependent and thus seems a bit unfair, but correct me if I'm wrong.
> Thanks.
>
|
#
8
| |||
| |||
Semaphore/Mutex interview question
joshc wrote:
> 1) What is the difference between a mutex and a binary semaphore?
> Thanks. Not sure for all RTS-es, but usually a mutex has priority inheritance, while a semaphore has not. Then a mutex is usually used for mutual exclusion of critical paths, while a semaphore is used for inter-thread synchronization and event notifications.
|
#
9
| |||
| |||
Semaphore/Mutex interview question
Adrian wrote: joshc wrote:
> 1) What is the difference between a mutex and a binary semaphore?
> Thanks.
> Not sure for all RTS-es, but usually a mutex has priority inheritance, while a semaphore has not. Then a mutex is usually used for mutual exclusion of critical paths, while a semaphore is used for inter-thread synchronization and event notifications. To be more specific, if you have two concurrent threads, with mutexes you will always have a pair of get/put mutex in each thread. With semaphores, you may wait (get) for the semaphore in one thread and put the semaphore in the other thread. Never use this with mutexes
|
#
10
| |||
| |||
Semaphore/Mutex interview question
In article <1158292191.257574.114150@h48g2000cwc.googlegroups. com>, joshc <josh.curtz@gmail.comwrote:
>So I had a phone interivew for an embedded software position with a >major communications company and was asked some questions that I didn't >seem to answer to the interviewer's satisfaction. enough, I got >called back for an on-site interview. Anyways, I want to run these >questions by others to see what the real answer is. You've gotten a number of slightly different opinions, which should be a strong hint that there's no True Definition
>1) What is the difference between a mutex and a binary semaphore? The most obvious answer that pops into my head comes from PSIX: A mutex has an owner, a semaphore (binary or otherwise) does not. Any old thread can post a semaphore, but only the owner of a mutex can unlock it. of the questions he asked during the interview was
>whether I had heard the term "munching". Well, after the interview I >looked it up and it is some term specific to VxWorks. Not having worked >with VxWorks before I decided to read a VxWorks manual online. It seems >like almost all his questions were related to VxWorks even though he >didn't say so. That's a new term by me (and an amusing way to add some functionality that simply belongs hidden in the c++ driver, now that I've looked it up). But then, I've done hardly any work with vxWorks, preferring "real"[1] operating systems (with memory protection and process models) for larger projects, and much lighter weight executives for smaller projects.
>Is there really one "correct" answer to the mutex vs binary sempahore >question? There definitely does seem to be a difference in VxWorks >as mutexes handle priority inversion. It seems to be S / library >dependent and thus seems a bit unfair, but correct me if I'm wrong. The reason a mutex *can* handle priority inversion is that there's a known owner to boost the priority of when the time comes. I suspect where the interviewer was leading with the "which one can you use in an interrupt handler" is deeper into the vxWorks-only space where an interrupt handler is running in the task environment of whatever thread it happened to interrupt. That makes the meaning of owning a mutex inside an interrupt handler somewhat problematic. quite common way of communicating out of an interrupt handler into task space is to have the interrupt handler signal a semaphore, which the task that's waiting for the interrupt is blocked on. The S will then make that task ready, and when time comes for a scheduling decision, it might even get the/a CPU. [1] K, that's flame bait. My bias showing again -- Steve Watt KD6GGD PP-ASEL-IA ICBM: 121W 56' 57.5" / 37N 20' 15.3" Internet: steve @ Watt.CM Whois: SW32-ARIN Free time? There's no such thing. It just comes in varying prices
|
#
11
| |||
| |||
Semaphore/Mutex interview question
joshc schrieb: routine and then asked if you could use a semaphore within an interrupt service routine. of the questions he asked during the interview was whether I had heard the term "munching". Well, after the interview I looked it up and it is some term specific to VxWorks. Not having worked with VxWorks before I decided to read a VxWorks manual online. It seems like almost all his questions were related to VxWorks even though he didn't say so. In the interrupt you should not wait a resource so you should only set the semaphore and never wait Adib. Is there really one "correct" answer to the mutex vs binary sempahore question? There definitely does seem to be a difference in VxWorks as mutexes handle priority inversion. It seems to be S / library dependent and thus seems a bit unfair, but correct me if I'm wrong.
> Thanks.
>
|
#
12
| |||
| |||
Quote:
|
#
13
| |||
| |||
Semaphore/Mutex interview question
This is the most dumbest question ever asked in interviews. "What is the diff between a mutex and a semaphore". Well the answer is: "which context are ya referring to ? Linux, VxWorks, Symbian, pThreads, Windows ? " Caus these words have diff connotations in diff Oses. Mutexes and binary semaphores are the same in Linux. Binary semaphores don't exist in pThreads, hence mutexes and semaphores (which the interviewer means to say counting semaphores) are different in pThreads. As already mentioned in this thread there are subtle differences in vxWorks as well. Thanks, Timothy Noel
|