
6 Jan
2008
6 Jan
'08
11:41 a.m.
On Jan 6, 2008 9:30 AM, Andrew Coppin
2. I have a situation where I have a thread generating some data and putting it into a mutable array, and another thread trying to read that data. Is there a way I can make the reader thread block if it tries to read a cell that hasn't been computed yet, but not introduce too much overhead for cells that have been filled in?
If your thread fills the array linearly, you could maintain a variable shared by those threads that say the last cell computed, and have the read thread check that before reading. I think this wouldn't create too much overhead, although it seems like there must be something cleverer somewhere. -- Felipe.