Saaa wrote:
Steven Schveighoffer wrote:
i.e. I want thread 1 to initialize elements 0, 1, and 2, and thread 2 to
initialize elements 3, 4, and 5:
thread1 = new ProcessingThread(arrayToInit[0..3]);
thread2 = new ProcessingThread(arrayToInit[3..6]);
thread1.start();
thread2.start();
Should be completely thread safe.
Could become more difficult if the distinction would be odd/even elements :P
Why??? If your threads have no bugs (i.e. the "odd" thread doesn't read
or write the "even" elements, and vice versa), then this should be easy!
Or creatures on a grid who can only see the cell they stand on :D
Then the only thing that has to be thread safe is the code that moves a
creature from cell to cell. And, of course, it has to guarantee that no
two creatures end up in the same cell.