Rick Molloy: Actor-based Programming in C++ - Control Flow versus Data Flow
- Posted: Aug 30, 2011 at 11:51 AM
- 43,741 Views
- 11 Comments
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
Right click “Save as…”
Rick Molloy is back and he's got some code and coding techniques to share. Thank you Rick! This tutorial/example is done in C++, but the concepts span languages (actor-based, data flow style of programming)
Here, Rick explores converting a simple loop to a set of actors or agents that communicate via message passing. In particular he looks at the difference between a "control flow" style implementation and a "data flow" style implementation. The actor based approach is great because it separates the guts of the work from the loop logic so code looks more like the flow charts we draw on our whiteboards.
But, there's some down sides with the control flow approach and implementing the data flow approach can be tricky. So Rick wanted to walk through an example of both to help illustrate the differences.
The downside to the control flow approach comes in when you have lots of agents, there tends to be either a 1:1 coupling of threads to tasks OR the tasks start taking on more than one responsibility and become less manageable.
A data flow style approach helps with this, because it decouples the 1:1 thread to task relationship but it can be an awkward refactoring if you're not used to it, it takes more code, and there aren't many examples available to look at on the web so Rick wanted to share another one.
Download the code for this demo (will work in VC++ 2010)