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
...全文
247 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Super.Jiju 2008-12-05
  • 打赏
  • 举报
回复
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

33,027

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧