import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; /** * Created by luochao on 14-1-4. */ public class ConcurrentQueue<Content> { private volatile Node<Content> head; private volatile Node<Content> tail; private final static AtomicReferenceFieldUpdater<ConcurrentQueue,Node> HEAD_UPDATER = AtomicReferenceFieldUpdater.newUpdater(ConcurrentQueue.class,Node.class,"head"); private final static AtomicReferenceFieldUpdater<ConcurrentQueue,Node> TAIL_UPDATER= AtomicReferenceFieldUpdater.newUpdater(ConcurrentQueue.class,Node.class,"tail"); private boolean casHead(final Node<Content> expect,final Node<Content> update){ return HEAD_UPDATER.compareAndSet(this,expect,update); } private boolean casTail(final Node<Content> expect,final Node<Content> update){ return TAIL_UPDATER.compareAndSet(this,expect,update); } public ConcurrentQueue(){ Node node = new Node(null,null); this.head = node; this.tail = node; } public void enqueue(Content content){ Node newNode = new Node(null,content); while (true){ Node t = tail; Node next = t.next; if(t == tail){//判断tail是否被修改 已经next一致性 if(next == null){ //从队列末尾入列 if(t.casNext(null, newNode)){ casTail(tail,newNode); return; } }else { casTail(tail,next); } } } } public boolean dequeue(Content content){ Node h = head; Node t = tail; Node next = h.next; while (true){ if(h == head){//double check 检查head是否一致 if(h == t){//判断是否为空队列 Is queue empty or Tail falling behind? if (next == null){ return false; } //Tail is falling behind. Try to advance it casTail(t,next); return true; }else{ if (casHead(h,next)){ return true; } } } } } private static class Node<Content>{ volatile Node next; Content value; Node(Node next, Content value) { this.next = next; this.value = value; } private boolean casNext(Node<Content> expect,Node<Content> update){ return NEXTUPDATE.compareAndSet(this,expect,update); } //字段更新器 param 1 字段所在类 2 更新字段的值 3 字段名称 基于cas private static final AtomicReferenceFieldUpdater<Node,Node> NEXTUPDATE = AtomicReferenceFieldUpdater.newUpdater(Node.class,Node.class,"next"); } }
Simple, Fast, and Practical Non-Blocking and Blocking Concurrent Queue Algorithms
refer:http://www.cs.rochester.edu/u/michael/PODC96.html
相关推荐
using select to implement socket multiplexing, and non-blocking, asynchronous IO
Simple, Fast, and Practical Non-Blocking and Blocking Concurrent Queue Algorithms
从书籍的github网站下载,并将其编译成html,然后手工在word中编辑,并转为pdf,格式很规范和完整,完美再现网页的效果。
Asynchronous, non-blocking SAP NW RFC SDK bindings for Pyt
Asynchronous, non-blocking SAP NW RFC SDK bindings for Nod
2.默认http与ajp请求实现non-blocking技术,即NIO技术。 3.多个应用发布的时候可以先打成jar包,然后打成一个总的war发布。(这句翻译不太准,意思大概是这样子的) 4.默认支持应用工程字符集为UFT-8 5.提升了日志...
The switch fabric delivers strictly non-blocking connectivity while completely canceling the first-order crosstalk. The 4×4 switching circuit consists of eight silicon microring-based spatial (de-)...
let-prove-blocking-queue:以多种方式证明阻塞队列的死锁状态
experiments 里面包含运行实验的运行文件,先将其他八个程序打开之后最后打开 main client new 然后让其自动运行 结果会保存在一个.txt里面。 源代码 有main client new 和 一个关于随机数生成的头文件 和 子文件
Blocking-Non-Blocking-IO-task2
用法下载仓库与mvn package一起mvn package 并使用java -jar target/spring-non-blocking-io-0.0.1-SNAPSHOT.jar 调用api并等待响应。这个怎么运作实例将在几秒钟内联机。 每次调用该服务时,一个简单的Thread.sleep...
Non-Blocking-Driving-Program
博主的博客Verilog之blocking & nonblocking assignments有些内容是参考了这篇英文文献的,其中对verilog中有关阻塞与非阻塞赋值语句的8种准则进行了详细的举例说明,读者可以下载文章进行详细阅读,以便更好地理解...
非阻塞IO(non-blocking IO) Linux下,可以通过设置socket使其变为non-blocking。当对一个non-blocking socket执行读操作时,流程是这个样子: 从图中可以看出,当用户进程发出read操作时,如果kernel中的数据还...
扩展性: 提供了较多的扩展接口以及默认扩展实现,使用者也可以根据需要自行定制扩展,具体见下面的框架扩展。 多消息协议: RPC 消息协议默认支持 Thrift、Kitex Protobuf、gRPC。Thrift 支持 Buffered 和 Framed ...
同步(synchronous) IO和异步(asynchronous) IO,阻塞(blocking) IO和非阻塞(non-blocking)IO分别是什么,到底有什么区别?这个问题其实不同的人给出的答案都可能不同,比如wiki,就认为asynchronous IO和non...
In data streams or web scenarios at highly variable and unpredictable rates, a good join algorithm should be able to "hide" the delays by continuing to output join results. The non-blocking algorithms...
异步阻塞队列npm install --save async-blocking-queueAsyncBlockingQueue import AsyncBlockingQueue from 'async-blocking-queue' ;var queue = new AsyncBlockingQueue ( ) ;// wait for next enqueue() ...
Reconfigurable non-blocking four-port optical router based on microring resonators
非阻塞算法java Java中的一些非阻塞算法