Argh. Stupid GMail sent it prematurely. On Mon, Mar 23, 2009 at 10:45 AM, Michael van der Gulik <mikevdg@gmail.com>wrote:
If, for example, you were trying to allocate an array of arrays concurrently, then I would write (using my namespaces :-) ):
array := Concurrent.Collections.Array new: 1000000000. " We ignore the cost of making this array to begin with :-) " array withIndexdo: [ :each :i | " each will always be nil. " array at: i put: (Array new: 10). ].
Concurrent.Collections.Array>>withIndexDo: aBlock | nThreads sema | nThreads := 1000. " Pull this from a system setting or something. " sema := Semaphore withSignals: 0-nThreads. " Needs implementing: signal it -1000 times (or -999 or -1001? Unsure) " 1 to: nThreads do: [ :i | [ (nThreads*i) to: (nThreads*i - 1) do: [ :j aBlock value: (self at: j) value: j ]
sema signal.
] fork ].
sema wait.
^ self.
Again, it probably won't just run without some bug fixing. And it won't work on non-closure Squeak anyway. Gulik. -- http://gulik.pbwiki.com/