免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2587 | 回复: 4
打印 上一主题 下一主题

请教Serializing Tokens的含义 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-09-02 16:57 |只看该作者 |倒序浏览
看文档的时候看到这样一个词Serializing Tokens ,不能理解是什么意思,

A thread may hold any number of serializing tokens.

A thread may hold serializing tokens through a thread yield or blocking condition, but must understand that another thread holding those tokens may be allowed to run while the first thread is not running (blocked or yielded away).

[ 本帖最后由 japonensis 于 2006-9-2 16:59 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2006-09-02 16:58 |只看该作者
搜索了一下也没有看到中文的解释,字面意思直译不知道怎么样。串行标记?

论坛徽章:
2
亥猪
日期:2014-03-19 16:36:35午马
日期:2014-11-23 23:48:46
3 [报告]
发表于 2006-09-02 17:29 |只看该作者
Copied entirely from http://en.wikipedia.org/wiki/Serializing_tokens

In computer science, serializing tokens are a concept in concurrency control arising from the ongoing development of DragonFly BSD. According to Matt Dillon, they are most akin to SPLs, except a token works across multiple CPUs while SPLs only work within a single CPU's domain.

Serializing tokens allow programmers to write multiprocessor-safe code without themselves or the lower level subsystems needing to be aware of every single entity that may also be holding the same token.

Tokens vs. Mutexes

Tokens are similar to mutexes in that they can, if used correctly, prevent multiple threads from accessing a shared resource at the same time. Unlike mutexes, however, they do NOT exclude other threads from accessing the resource while they are blocked or asleep. In general terms, they're both locks: your thread gets a lock (which prevents other threads from having it), does some work, and then releases it for another thread to use.

It's important here to recall how threads interact with each other when sharing resources. There are a number of ways that a thread can be stopped and another thread to be started:

     1. Timeslicing: the scheduler tries to ensure that all threads get a fair chance to run, so it runs each thread for a brief period of time (a timeslice) and then switches to another thread.
     2. Concurrent Execution: In multiprocessor computers, your thread may also be run at exactly the same time as another thread on a different CPU.
     3. Preemption: A thread may be preempted by a higher priority thread, such as a hardware interrupt or LWKT.
     4. Voluntary Blocking: A thread may voluntarily block (aka "go to sleep" ) if it has to wait for something, has no work to do, or calls a function that blocks-- note that even the call to acquire a lock can block.

Remember: the purpose of a lock is to keep other threads out while your thread is working on something. This table summarizes the situations in which tokens and mutexes work correctly to keep other threads "out".



So what's the big deal? It seems like mutexes are the clear winner-- and in some cases it's important to be able to block and keep a lock. However, they also cause problems such as Deadlocks and Priority inversions. Dealing with these issues is very difficult and requires coordination at many different levels of the kernel:
   "In fact, the fact that tokens do not deadlock coupled with the fact
   that there is no expectation of atomicity for earlier acquired tokens
   when later operations block leads to a great deal of code simplification.
   If you look at FreeBSD-5, you will notice that FreeBSD-5 passes held
   mutexes down the subroutine stack quite often, in order to allow some
   very deep procedural level to temporarily release a mutex in order to
   switch or block or deal with a deadlock.  There is a great deal of
   code pollution in FreeBSD-5 because of this (where some procedures
   must be given knowledge of the mutexes held by other unrelated procedures
   in order to function properly)." -- Matt Dillon

Obviously Matt has reason to promote his own solution to deadlocking, but he has a point: serializing tokens do a fine job of locking out other threads as long as you don't block while holding them. If you do, another thread will steal the lock and possibly change the data you were working on. You will reacquire the token when you are awakened, but you will have to make sure that your data is still consistent.

Serializing Tokens In Action

To show how serializing tokens actually work, let's see some pseudocode and what's going on behind the scenes.



References
A mailing list thread where Matt Dillon explains tokens in great detail

[ 本帖最后由 gvim 于 2006-9-2 17:31 编辑 ]

论坛徽章:
2
亥猪
日期:2014-03-19 16:36:35午马
日期:2014-11-23 23:48:46
4 [报告]
发表于 2006-09-02 17:37 |只看该作者
看了wiki的说明和部分邮件,我感觉有点像令牌环那么个东西。

论坛徽章:
0
5 [报告]
发表于 2006-09-04 08:47 |只看该作者
这是df的同步手段吧.应该是防止死锁的.死锁的一个必要条件是xxx环路,使用这种串行后无法形成环路,确保没有死锁,似乎是如此.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP