• 全部
  • 问答

Non-Blocking Algorithm - Introduction

hellwolf 2008-11-30 11:14:50
原文: http://blog.chinaunix.net/u/8057/showart_1672481.html

Non-Blocking Algorithm - Introduction

Author: ZC Miao <hellwolf.misty át gmail dôt com>

Date: Saturday, November 29 2008

In computer science, non-blocking synchronization ensures that threads competing for a shared resource do not have their execution indefinitely postponed by mutual exclusion. A non-blocking algorithm is lock-free if there is guaranteed system-wide progress; wait-free if there is also guaranteed per-thread progress1.

This simple diagram shows more clearly the idea:

+------------------------------+--------------------------------+
| | |
| Mutual Exclusion | Non-Blocking |
| | |
| | +-------------------------+ |
| | | | | | |
| | H | | | Lock-Freedom | |
| | y | | | | |
| | b | | | +------------------+ | |
| Blocking | r | Busy-Waiting| | | | | |
| | i | (Polling) | | | Wait-Freedom | | |
| | d | | | | | | |
| | s | | | +------------------+ | |
| | | | | | |
| | +-------------------------+ |
| | |
+------------------------------+--------------------------------+

Using mutual exclusion is the most instinctive and easiest way to protect data from corruption in concurrent multi-threaded programming, which simply creates a critical region around the operations of data structure. It works fine most of the situations, but in some situations, lock is just too expensive or even not available. One example is for some ISR(Interrupt Service Routines), if it disables the interruption, then the scheduler will not be run until they open the interruption again, if it also waits for some resources which is hold by some task, then it will never available because scheduler stops. Another example is in RTOS, higher priority wait for the lower priority task to release the resource, then it causes priority-inversion. So, non-blocking algorithms are born to solve these problem without using mutual exclusions.

Valois published his most cited paper talking about lock-free data structure at 19952. But unfortunately, there are some mistakes with the memory management method introduced by Valois3.

But algorithms from Valois needs special memory management, and it's just too complicated to use. Michael and Scott published their own algorithms based on the idea of cooperative task from Valois4.

There's another more detailed notes on lock-free and wait-free algorithms area from Internet5.

1. Non-blocking synchronization from Wikipedia http://en.wikipedia.org/wiki/Lock-free_and_wait-free_algorithms#Wait-freedom

2. J.D. Valois, Lock-Free Data Structures PhD Thesis, Rensselaer Polytechnic Institute, Department of Computer Science, 1995.

3. Maged M. Michael, Michael L. Scott Correction of a Memory Management Method for Lock-Free Data Structures, Department of Computer Science University of Rochester, 1995.

4. Maged M. Michael Michael L. Scott, Simple, Fast, and Practical Non-Blocking and Blocking Concurrent Queue Algorithms,, Department of Computer Science University of Rochester, 1995.

5. Some notes on lock-free and wait-free algorithms http://www.audiomulch.com/~rossb/code/lockfree
...全文
182 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
niubility
回复
hmsuccess 2008-12-05
mark
回复
hellwolf 2008-12-05
Update:
原文: http://blog.chinaunix.net/u/8057/showart_1672481.html

Non-Blocking Algorithm - Introduction

Author: ZC Miao <hellwolf d o t misty a,t gmail d o t com>

Revision:

* 2008-12-04

Add revision information.
* 2008-11-29

First revision.

Non-Blocking Algorithm Introduction

In computer science, non-blocking synchronization ensures that threads competing for a shared resource do not have their execution indefinitely postponed by mutual exclusion. A non-blocking algorithm is lock-free if there is guaranteed system-wide progress; wait-free if there is also guaranteed per-thread progress1.

This simple diagram shows more clearly the idea:

+------------------------------+--------------------------------+
| | |
| Mutual Exclusion | Non-Blocking |
| | |
| | +-------------------------+ |
| | | | | | |
| | H | | | Lock-Freedom | |
| | y | | | | |
| | b | | | +------------------+ | |
| Blocking | r | Busy-Waiting| | | | | |
| | i | (Polling) | | | Wait-Freedom | | |
| | d | | | | | | |
| | s | | | +------------------+ | |
| | | | | | |
| | +-------------------------+ |
| | |
+------------------------------+--------------------------------+

Using mutual exclusion is the most instinctive and easiest way to protect data from corruption in concurrent multi-threaded programming, which simply creates a critical region around the operations of data structure. It works fine most of the situations, but in some situations, lock is just too expensive or even not available. One example is for some ISR(Interrupt Service Routines), if it disables the interruption, then the scheduler will not be run until they open the interruption again, if it also waits for some resources which is hold by some task, then it will never available because scheduler stops. Another example is in RTOS, higher priority wait for the lower priority task to release the resource, then it causes priority-inversion. So, non-blocking algorithms are born to solve these problem without using mutual exclusions.

Valois published his most cited paper talking about lock-free data structure at 19952. But unfortunately, there are some mistakes with the memory management method introduced by Valois3.

But algorithms from Valois needs special memory management, and it's just too complicated to use. Michael and Scott published their own algorithms based on the idea of cooperative task from Valois4.

There's another more detailed notes on lock-free and wait-free algorithms area from Internet5.

1. Non-blocking synchronization from Wikipedia http://en.wikipedia.org/wiki/Lock-free_and_wait-free_algorithms#Wait-freedom

2. J.D. Valois, Lock-Free Data Structures PhD Thesis, Rensselaer Polytechnic Institute, Department of Computer Science, 1995.

3. Maged M. Michael, Michael L. Scott Correction of a Memory Management Method for Lock-Free Data Structures, Department of Computer Science University of Rochester, 1995.

4. Maged M. Michael Michael L. Scott, Simple, Fast, and Practical Non-Blocking and Blocking Concurrent Queue Algorithms,, Department of Computer Science University of Rochester, 1995.

5. Some notes on lock-free and wait-free algorithms http://www.audiomulch.com/~rossb/code/lockfree
回复
hityct1 2008-12-01
mark
回复
相关推荐
发帖
数据结构与算法
创建于2007-08-27

3.2w+

社区成员

数据结构与算法相关内容讨论专区
申请成为版主
帖子事件
创建了帖子
2008-11-30 11:14
社区公告
暂无公告