Skip to content

Instantly share code, notes, and snippets.

@binshuohu
binshuohu / akk-stream-graph-cycles.md
Last active November 17, 2015 14:23
Akka Stream Graph Cycles Illustrated

今天阅读akka streams文档时,Graph一节里最后一小段关于cycles, liveness and deadlocks的内容非常有趣。初次阅读,第一时间没有理解这部分内容,仔细想了一下才反应过来。这里通过画图来说明会比较容易理解。

原文档中的例子如下(稍稍修改了一下,方便讲解)

// WARNING! The graph below deadlocks!
RunnableGraph.fromGraph(FlowGraph.create() { implicit b =>
  import FlowGraph.Implicits._
  
  val merge = b.add(Merge[Int](2).withAttributes(Attributes.inputBuffer(1, 1)))       //use extremely small buffer
 val bcast = b.add(Broadcast[Int](2).withAttributes(Attributes.inputBuffer(1, 1))) //to better expose the problem
class Solution {
struct Ctx
{
int* array;
int len;
};
public:
double findMedianSortedArrays(int A[], int m, int B[], int n) {
if((m+n) == 0)
return 0;