One consumer, one producer problem:
[url="http://www.drdobbs.com/parallel/writing-lock-free-code-a-corrected-queue/210604448?pgno=1"]Lock Free Queue[/url]
Basically add one a separator in a list then nodes between separator and last is owned by consumer, the node between first and separator should be collected by producer and producer only append new nodes to the last.
This problem is also described in the book [b]Java Concurrency in Practice[/b].
[img]http://dl.iteye.com/upload/attachment/0075/8103/2faacb36-a547-3510-848e-5e73a0b8339b.gif[/img]
见上图,producer从last处插入结点,consumer从divider处开始消耗结点。
[url="http://www.drdobbs.com/parallel/writing-lock-free-code-a-corrected-queue/210604448?pgno=1"]Lock Free Queue[/url]
Basically add one a separator in a list then nodes between separator and last is owned by consumer, the node between first and separator should be collected by producer and producer only append new nodes to the last.
This problem is also described in the book [b]Java Concurrency in Practice[/b].
[img]http://dl.iteye.com/upload/attachment/0075/8103/2faacb36-a547-3510-848e-5e73a0b8339b.gif[/img]
见上图,producer从last处插入结点,consumer从divider处开始消耗结点。