I accidently posted the ``fix'' which was to serialize the outer execution loop. But, what I had before was:

1
2
3
4
5
6
7
let aLoopingFun () =
    // ...
    seq {      
    for i=0 to n do
        myFun ()
    } |> Async.Parallel |> Async.RunSynchronously
    // ...

Is there a good way to handle hierarchies of Async loops? Maybe some way to restrict the inner loops to a certain number of threads?

By on 1/27/2010 11:27 AM ()

In this case, you should have the inner loop not call RunSynchonously, just return the async object and have the outer function run it. E.g.

1
2
3
4
5
let inner() : async<Whatever> = // instead of returning Whatever
    blah async blah |> Async.Parallel

let outer() =
    blah seq{ for i=0 to n do yield inner() } |> Async.Parallel |> Async.RunSynchronously

I've heard the thesis floated that there should be at most one call to RunSynchronously in your program. That's probably a little too strong, but the general idea that you should just be 'consing up async structures, bubbling up to the top of your program' before you parallize them and kick them off to run at once... that is a good pattern.

By on 1/27/2010 11:37 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper