Hacker News new | ask | show | jobs
by HisGraceTheDuck 3239 days ago
After a quick look at the code (I'm probably missing subtleties):

The "state" array stores the state of the cells in the life simulation in the lowest bit of each int in the array. The rest of the bits are used to store the count of the current generation for that cell.

Each thread can then examine cells independently and determine whether there's enough information in the cell's neighbours (taking generations into account) to update the cell's state (and increment the generation).

The trick is that even though the threads could be reading and writing the same cells at the same time, they will only ever write the same thing and so it doesn't matter.