Following this advice, I use the following code:
let nThreads = 3;
let threads : [var ?(async*())] = Array.init(nThreads, null);
for (threadNum in threads.keys()) {
threads[threadNum] := ?runThread({threadNum; var referenceTree; var rng; index; guidGen});
};
label F for (topt in threads.vals()) {
let ?t = topt else {
Debug.trap("programming error");
};
await* t;
// break F;
}
But contrary to how I understand this answer, the threads don’t run in parallel (despite every thread contains plenty of await
s), but run in order: 0, 1, 2.
Moreover, contrary to the answer that says that Motoko futures are eager, if I uncomment break F
, then only the first thread runs (the answer seems to imply that all three threads will be run at the point of the first await* t
).
What I misunderstand? How to make several threads to run in parallel? I mean collaborative parallelism at points of await
s (and await*
s?)