Race Condition in Fibonacci Example? RRS feed

  • Question

  • In the Fibonacci example on page 8 of the "Axum Programmer's Guide", if ProcessResult() ever decrements numCount before MainAgent() has finished generating the input numbers, it seems that the latter will never send the full quota of inputs, and so ProcessResult() will not terminate. Is there some aspect of OrderedInteractionPoint, the forwarding operator or agents that guarantees the completion of MainAgent() before ProcessResult() starts?
    Thursday, May 14, 2009 12:27 PM


  • Yes, the Axum programming model is safe from a race-condition perspective: no writer may execute at the same time as a reader (or other writer) of the same state partition. This is the language's fundamental value proposition, that we have removed race conditions as a programmer concern (as long as you're not PInvoking into native code).

    In this case, we're talking about agent state. The main agent runs uninterrupted since there are no receive statements. Instances of the Fibonacci function, having no side-effects, may run in parallel with each other, per the language definition. In this particular case, because Fib is naively implemented, that's the stage in the pipeline that will take any time, so you get some parallelism there. Since PrintResult has side-effects, it's executed as a writer and is therefore not going to be run in parallel with anything else.

    In reality, and this is a runtime deficiency, the Fibonacci instances will not be executed in parallel: we shelved the implementation for a variety of reasons, so in the CTP, the instances will be executed serially. With pipelines, you get parallelism between side-effect-free stages, and between branches of the network. An alternative version that would give you some (4-way) parallelism with the current implementation is this:

    numbers -<: { Fibonacci, Fibonacci, Fibonacci, Fibonacci } >>- ProcessResult;

    But it won't preserve the order of results. In a subsequent release, we will both preserve the order and realize parallelism in the same stage with the original code from the programmer's guide.


    Thursday, May 14, 2009 3:13 PM