[OT] Retreating from Iraq
Sean Kelly
sean at invisibleduck.org
Mon Oct 13 15:15:48 PDT 2008
Andrei Alexandrescu wrote:
> Suppose that a miracle happen and the decision is taken at the highest
> level to retreat all of US military presence from Iraq. That will take a
> while, but sending the orders quickly is a must.
>
> For utmost certainty, all orders are to be sent via phone and down the
> command chain, and only to direct subordinates. Each officer has a
> variable number of subordinates. Initially the president calls his
> immediate subordinates, who call their immediate subordinates, etc. Each
> call can be assumed to take the same amount of time.
>
> Devise an algorithm that ensures every foot soldier gets the news as
> quickly as possible, show it is correct, and show it is fast.
Ah, we're finally getting into concurrent programming :-) I'm sure the
syntax could be made more D 2.0-like, but something like this should do
the trick:
class Soldier
{
Soldier[] subordinates;
void notify()
{
foreach( s; subordinates )
pool.add( &s.notify() );
pool.add( &flee() );
}
void flee()
{
// make 'this' actually flee
}
}
Assume 'pool' is a global thread pool with some number of worker threads
proportional to the number of cores on the system. This will issue
instructions for all Soldiers to flee in an optimally parallel manner
for the target system.
Sean
More information about the Digitalmars-d
mailing list