Function makeIsolatedArray
Creates a new isolated array.
Prototype
Isolated!(T[]) makeIsolatedArray(T)( size_t size );
Examples
import vibe.core.concurrency; void compute(Tid tid, Isolated!(double[]) array, size_t start_index) { foreach( i; 0 .. array.length ) array[i] = (start_index + i) * 0.5; send(tid, array.move()); } void main() { import std.stdio; // compute contents of an array using multiple threads auto arr = makeIsolatedArray!double(256); // partition the array (no copying takes place) size_t[] indices = [64, 128, 192, 256]; Isolated!(double[])[] subarrays = arr.splice(indices); // start processing in threads Tid[] tids; foreach( i, idx; indices ) tids ~= spawn(&compute, thisTid, subarrays[i].move(), idx); // collect results auto resultarrays = new Isolated!(double[])[tids.length]; foreach( i, tid; tids ) resultarrays[i] = receiveOnly!(Isolated!(double[])).move(); // BUG: the arrays must be sorted here, but since there is no way to tell // from where something was received, this is difficult here. // merge results (no copying takes place again) foreach( i; 1 .. resultarrays.length ) resultarrays[0].merge(resultarrays[i]); // convert the final result to immutable auto result = resultarrays[0].freeze(); writefln("Result: %s", result); }
Authors
Sönke Ludwig
Copyright
© 2013 RejectedSoftware e.K.
License
Subject to the terms of the MIT license, as written in the included LICENSE.txt file.