讨论mutex与semaphore区别的列表

本文讨论了在嵌入式软件面试中关于互斥锁与二进制信号量的问题。多位专业人士从不同角度解释了这两种同步机制的区别,并探讨了它们在特定操作系统如VxWorks中的实现细节。
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
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
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
本系统采用Python编程语言中的Flask框架作为基础架构,实现了一个面向二手商品交易的网络平台。该平台具备完整的前端展示后端管理功能,适合用作学术研究、课程作业或个人技术能力训练的实际案例。Flask作为一种简洁高效的Web开发框架,能够以模块化方式支持网站功能的快速搭建。在本系统中,Flask承担了核心服务端的角色,主要完成请求响应处理、数据运算及业务流程控制等任务。 开发工具选用PyCharm集成环境。这款由JetBrains推出的Python专用编辑器集成了智能代码提示、错误检测、程序调试自动化测试等多种辅助功能,显著提升了软件编写维护的效率。通过该环境,开发者可便捷地进行项目组织问题排查。 数据存储部分采用MySQL关系型数据库管理系统,用于保存会员资料、产品信息及订单历史等内容。MySQL具备良好的稳定性和处理性能,常被各类网络服务所采用。在Flask体系内,一般会配合SQLAlchemy这一对象关系映射工具使用,使得开发者能够通过Python类对象直接管理数据实体,避免手动编写结构化查询语句。 缓存服务由Redis内存数据库提供支持。Redis是一种支持持久化存储的开放源代码内存键值存储系统,可作为高速缓存、临时数据库或消息代理使用。在本系统中,Redis可能用于暂存高频访问的商品内容、用户登录状态等动态信息,从而加快数据获取速度,降低主数据库的查询负载。 项目归档文件“Python_Flask_ershou-master”预计包含以下关键组成部分: 1. 应用主程序(app.py):包含Flask应用初始化代码及请求路径映射规则。 2. 数据模型定义(models.py):通过SQLAlchemy声明数据库表对应的类结构。 3. 视图控制器(views.py):包含处理各类网络请求并生成回复的业务函数,涵盖账户管理、商品展示、订单处理等操作。 4. 页面模板目录(templates):存储用于动态生成网页的HTML模板文件。 5. 静态资源目录(static):存放层叠样式表、客户端脚本及图像等固定资源。 6. 依赖清单(requirements.txt):记录项目运行所需的所有第三方Python库及其版本号,便于环境重建。 7. 参数配置(config.py):集中设置数据库连接参数、缓存服务器地址等运行配置。 此外,项目还可能包含自动化测试用例、数据库结构迁移工具以及运行部署相关文档。通过构建此系统,开发者能够系统掌握Flask框架的实际运用,理解用户身份验证、访问控制、数据持久化、界面动态生成等网络应用关键技术,同时熟悉MySQL数据库运维Redis缓存机制的应用方法。对于入门阶段的学习者而言,该系统可作为综合性的实践训练载体,有效促进Python网络编程技能的提升。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
在当代储能装置监控技术领域,精确测定锂离子电池的电荷存量(即荷电状态,SOC)是一项关键任务,它直接关系到电池运行的安全性、耐久性及整体效能。随着电动车辆产业的迅速扩张,业界对锂离子电池SOC测算的精确度稳定性提出了更为严格的标准。为此,构建一套能够在多样化运行场景及温度条件下实现高精度SOC测算的技术方案具有显著的实际意义。 本文介绍一种结合Transformer架构容积卡尔曼滤波(CKF)的混合式SOC测算系统。Transformer架构最初在语言处理领域获得突破性进展,其特有的注意力机制能够有效捕捉时间序列数据中的长期关联特征。在本应用中,该架构用于分析电池工作过程中采集的电压、电流温度等时序数据,从而识别电池在不同放电间的动态行为规律。 容积卡尔曼滤波作为一种适用于非线性系统的状态估计算法,在本系统中负责对Transformer提取的特征数据进行递归融合实时推算,以持续更新电池的SOC值。该方法增强了系统在测量噪声干扰下的稳定性,确保了测算结果在不同环境条件下的可靠性。 本系统在多种标准驾驶循环(如BJDST、DST、FUDS、US06)及不同环境温度(0°C、25°C、45°C)下进行了验证测试,这些条件涵盖了电动车辆在实际使用中可能遇到的主要工况气候范围。实验表明,该系统在低温、常温及高温环境中,面对差异化的负载变化,均能保持较高的测算准确性。 随附文档中提供了该系统的补充说明、实验数据及技术细节,核心代码模型文件亦包含于对应目录中,可供进一步研究或工程部署使用。该融合架构不仅在方法层面具有创新性,同时展现了良好的工程适用性测算精度,对推进电池管理技术的进步具有积极意义。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值