On 16-05-2012 05:03, H. S. Teoh wrote:
On Wed, May 16, 2012 at 04:35:17AM +0200, Alex Rønne Petersen wrote:
Hi,

Suppose that I have an AA that I'm doing lookups on from one thread,
and writing to in another. Is this safe at all? Naturally, I'm
willing to accept the data races involved, but the question is
whether the concurrent lookup + mutation is guaranteed to be safe.
[...]

Safe as in, no memory corruption? Or safe as in, the data will be
consistent (barring any data races)?

As in no memory corruption.


Memory safety I'm not sure, I _think_ it might be safe, but I have my
doubts; data consistency, likely not, because you could potentially be
reading partially-copied data (say the mutator was assigning new data to
an existing key and the reader is reading that same data
simultaneously; you may be seeing a partial copy of the new data
intermixed with the old data).

Assuming the AA implementation only does aligned reads/writes, there should be no problem with word tearing on any modern architecture. But I don't know if it does that...



T


--
- Alex

Reply via email to