in reply to Depth First Search

This starts processing the nodes in DFS order.

use threads; use threads::shared; use constant NUM_WORKERS => ...; sub process { my ($node) = @_; ... } { my $tree: shared = ...; my $q = Thread::Queue->new(NUM_WORKERS); for (1..NUM_WORKERS) { async { while (my $node = $q->dequeue()) { process($node); } }; } my @todo = $tree; while (@todo) { my $node = pop(@todo); $q->enqueue($node); push @todo, $node->children(); } $q->end(); $_->join() for threads->list(); }

Replies are listed 'Best First'.
Re^2: Depth First Search
by BrowserUk (Patriarch) on Aug 09, 2016 at 20:52 UTC

    That pseudo code is entirely broken.

    1. It doesn't do a depth first search.

      It processes the root node; then its children; then their children; then ....

    2. It provides no possibility for "all children at the same stage will be analyse together"
    3. It makes no attempt to do any locking of the shared data structure.

    And if you corrected all of that, it would run 10x slower than a single threaded solution.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.