讨论mutex与semaphore区别的列表

Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a   Time spent in forums: Reputation Power:
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.

Reply With Quote
  # 2  
Old September 15th, 2006, 06:20 AM
Boudewijn Dijkstra
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a   Time spent in forums: Reputation Power:
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/

Reply With Quote
  # 3  
Old September 15th, 2006, 07:20 AM
Ed Prochak
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a   Time spent in forums: Reputation Power:
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

Reply With Quote
  # 4  
Old September 15th, 2006, 07:49 AM
joshc
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a   Time spent in forums: Reputation Power:
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?

Reply With Quote
  # 5  
Old September 16th, 2006, 06:19 AM
Matthew Hicks
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a   Time spent in forums: Reputation Power:
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. >

Reply With Quote
  # 6  
Old September 17th, 2006, 06:19 AM
Don
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a   Time spent in forums: Reputation Power:
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).

Reply With Quote
  # 7  
Old September 18th, 2006, 09:19 PM
Steve
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a   Time spent in forums: Reputation Power:
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. >

Reply With Quote
  # 8  
Old September 19th, 2006, 01:49 PM
Adrian
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a   Time spent in forums: Reputation Power:
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.

Reply With Quote
  # 9  
Old September 19th, 2006, 02:19 PM
Adrian
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a   Time spent in forums: Reputation Power:
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

Reply With Quote
  # 10  
Old September 22nd, 2006, 06:20 AM
Steve Watt
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a   Time spent in forums: Reputation Power:
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

Reply With Quote
  # 11  
Old September 28th, 2006, 06:10 AM
Adib Taraben
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a   Time spent in forums: Reputation Power:
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. >

Reply With Quote
  # 12  
Old October 23rd, 2006, 12:25 PM
vikont vikont is offline
<script type="text/javascript"> vbmenu_register("postmenu_6293050", true); </script>
Registered User
Dev Archives Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 1 vikont User rank is Just a Lowly Private (1 - 20 Reputation Level)   Time spent in forums: 30 m 43 sec Reputation Power: 0
Quote:
Originally Posted by joshc
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.
It's really this simple. The task that owns mutex semaphore can take it again, while if it attempts to take again the binary semaphore that it owns, it'll fail. In other words, vxworks mutex sema are recursive (re-entrant), while binary are not. Yes, I have access to vxworks source code, so I looked it up.

Reply With Quote
  # 13  
Old October 11th, 2007, 03:22 PM
tnoelhere tnoelhere is offline
<script type="text/javascript"> vbmenu_register("postmenu_7059395", true); </script>
Registered User
Dev Archives Newbie (0 - 499 posts)
 
Join Date: Oct 2007
Posts: 1 tnoelhere User rank is Just a Lowly Private (1 - 20 Reputation Level)   Time spent in forums: 28 m 43 sec Reputation Power: 0
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

Reply With Quote
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在信号处理领域,DOA(Direction of Arrival)估计是一项关键技术,主要用于确定多个信号源到达接收阵列的方向。本文将详细探讨三种ESPRIT(Estimation of Signal Parameters via Rotational Invariance Techniques)算法在DOA估计中的实现,以及它们在MATLAB环境中的具体应用。 ESPRIT算法是由Paul Kailath等人于1986年提出的,其核心思想是利用阵列数据的旋转不变性来估计信号源的角度。这种算法相比传统的 MUSIC(Multiple Signal Classification)算法具有较低的计算复杂度,且无需进行特征值分解,因此在实际应用中颇具优势。 1. 普通ESPRIT算法 普通ESPRIT算法分为两个主要步骤:构造等效旋转不变系统和估计角度。通过空间平移(如延时)构建两个子阵列,使得它们之间的关系具有旋转不变性。然后,通过对子阵列数据进行最小二乘拟合,可以得到信号源的角频率估计,进一步转换为DOA估计。 2. 常规ESPRIT算法实现 在描述中提到的`common_esprit_method1.m`和`common_esprit_method2.m`是两种不同的普通ESPRIT算法实现。它们可能在实现细节上略有差异,比如选择子阵列的方式、参数估计的策略等。MATLAB代码通常会包含预处理步骤(如数据归一化)、子阵列构造、旋转不变性矩阵的建立、最小二乘估计等部分。通过运行这两个文件,可以比较它们在估计精度和计算效率上的异同。 3. TLS_ESPRIT算法 TLS(Total Least Squares)ESPRIT是对普通ESPRIT的优化,它考虑了数据噪声的影响,提高了估计的稳健性。在TLS_ESPRIT算法中,不假设数据噪声是高斯白噪声,而是采用总最小二乘准则来拟合数据。这使得算法在噪声环境下表现更优。`TLS_esprit.m`文件应该包含了TLS_ESPRIT算法的完整实现,包括TLS估计的步骤和旋转不变性矩阵的改进处理。 在实际应用中,选择合适的ESPRIT变体取决于系统条件,例如噪声水平、信号质量以及计算资源。通过MATLAB实现,研究者和工程师可以方便地比较不同算法的效果,并根据需要进行调整和优化。同时,这些代码也为教学和学习DOA估计提供了一个直观的平台,有助于深入理解ESPRIT算法的工作原理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值