Anyone have thoughts on using the Blackboard Pattern in this way?

后端 未结 1 2037
粉色の甜心
粉色の甜心 2021-02-03 11:51

Does anyone have any thoughts of the Blackboard concept from p.165 of \'The Pragmatic Programmer\'?

I want to have several small sub-systems (DLLs and EXEs) mostly indep

1条回答
  •  既然无缘
    2021-02-03 12:03

    The concept of a blackboard is that multiple independent processes run and update the blackboard as they work out pieces of it. A classic example is speech recognition. The input data is the audio that is to be recognized. The audio can be segmented and multiple threads start matching the snippets to words. As each thread finds matching words, they update the blackboard with the translation up to this point. As phrases start to be assembled another thread can do grammar checking to verify the choices the various recognizer threads are making. If a word has a low confidence and violates the grammar, the piece can be rerun looking for alternatives. This might even result in re-partitioning the audio data as stutters and pauses are resolved.

    As the phrases become sentences, even larger views can be taken and the various options for homophones (pair, pare) can be resolved. All of this is done by having the blackboard open to all of the processes and "locks" only being applied as they various results roll in.

    Using a database as your blackboard makes some sense because you get transactions "for free", but it would depend on how aggressively the data is being updated and re-read. If it is happening very quickly the round trips would add up and make an in memory structure more reasonable.

    Your idea of a mediator makes sense as it creates a single lock point... and blackboard algorithms rarely encounter the A->B, B->A style deadlocks because they ask for all the data elements up front. Beyond that, giving up on a lock isn't a large penalty as the various sub-tasks will be restarting all the time as the data rolls in. Subscribers to the board will need to be notified when the data they have has become obsolete, which could be done with callbacks which would restart the task with the newest data.

    As far as the comment about a workflow: the major difference here is that most workflows are coordinated by a master process that takes the state just entered and makes decisions as to what states become available for the data to move within. While there may be independent actors, they rarely get involved in "outdoing" one another by creating better results (which other tasks will then use). In other words, a workflow is usually a very constrained set of states that data marches through, while a blackboard is almost a free-for all of independent activity. (That said, a blackboard could be behind your workflow: http://sunsite.informatik.rwth-aachen.de/Publications/CEUR-WS/Vol-247/FORUM_15.pdf)

    I can't think of any C# examples of the pattern that I have seen, and the type of work I do doesn't have much call for it (the computations being deterministic). Doing some searches find references in other languages, but none that appear of great quality.

    0 讨论(0)
提交回复
热议问题