信号量:我在哪里可以了解基本概念,例如许可、公平、闯入等

发布于 2024-11-04 11:10:17 字数 722 浏览 1 评论 0原文

developer.android.com 中的 Semaphore 类概述 看起来相当不错 - 对于那些已经熟悉概念和术语的人来说。

我熟悉其中的一些首字母缩略词和其他术语(例如 FIFO、锁定等),但也熟悉其他术语,例如 permitsfairnessbarging 对我来说是新的。

您能推荐一个好的在线资源来解释这些概念吗? (我大概可以弄清楚什么是许可公平,但是闯入目前还是未知数)。

编辑:收到下面的两个答案后,我意识到我需要刷新信号量(重新获取()术语)。我发现以下资源很有用:

  1. Semaphore_(programming)
  2. 信号量简介 作者: 理查德·霍尔博士

The Semaphore class overview in developer.android.com looks pretty good - for those who are already familiar with the concepts and terminology.

I am familiar with some of the acronyms and other jargon there (e.g. FIFO, lock, etc.) but others such as permits, fairness and barging are new to me.

Can you recommend a good online source for explaining these concepts? (I can probably figure out what permits and fairness are but barging is an unknown at this point).

EDIT: After receiving the two answers below, I realized that I need a refresh on semaphores (to re-acquire() terminology). I found the following resources to be useful:

  1. Semaphore_(programming)
  2. Introduction to Semaphores by
    Dr. Richard S. Hall

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

听不够的曲调 2024-11-11 11:10:17

我自己没有遇到过这些,但我想我应该研究并总结我的发现,因为内嵌答案比外部链接更好(尽管,是的,OP是在推荐阅读之后):

允许是允许信号量保护代码的并发访问数。虽然信号量通常是简单的互斥体,但有时需要有多个线程接触代码。这类似于给呼叫中心打电话,其中一个电话号码连接到 8 条线路/运营商。

公平是指按照严格的先请求者顺序向请求者提供信号量。继续与呼叫中心类比,这意味着等待队列是严格的 FIFO。

插入本质上是一种带外请求,它将线程置于信号量队列的顶部。类比是优先客户(或内部呼叫)进入呼叫中心队列的顶部,而不是等待轮到他们。

如果公平性闯入均未指定,则根据上下文切换的时间,授予对最近请求的访问权限符合规范。 “电话”就像打给公司总机/接待处的电话,即使呼叫处于等待应答状态,您也可能会幸运地在一个呼叫结束和另一个呼叫取消保持之间响铃。

如果我弄错了,请通过评论告诉我,我会修正/修改我的答案。

Hadn't come across these myself, but thought I'd research and summarise my findings as it's better to in-line answers than link externally (although, yes, the OP is after recommending reading):

permits are the number of concurrent accesses allowed to the semaphore-protected code. Although often semaphores are simple Mutex's, it is sometimes desirable to have more than one thread touching code. This is similar to phoning a call-centre, where there's one phone number connected to 8 lines/operators.

fairness is when a semaphore is made available to requesters in strict order of who requested first. Staying with the call-centre analogy, this means the on-hold queue is a strict FIFO.

barging is essentially an out-of-band request, that puts a thread to the top of the queue for a semaphore. The analogy is where preferred customers (or internal calls) go to the top of a call-centre queue, rather than waiting their turn.

If neither fairness nor barging are specified, then it's within spec to grant access to the most recent request, depending on timing of context switches. The 'phone analogy is a call to a company switchboard/reception, where even if calls are on hold waiting for answer, you may get lucky and ring between one call ending and another call being taken off-hold.

Let me know through comments if I've got this wrong, and I'll fix / cw my answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文