For what it's worth, I don't believe the following to be true:
dennisat, on 06 December 2014 - 01:23 PM, said:
Compare/exchange simply allows you to update a pointer atomically - it doesn't matter what kind of data it is. It does, however, matter that the data structures using it are immutable, which is why the code was quite complex: to add or remove a sound source (in a List in the Dictionary) it must create a new List (with the item added/removed) and a new Dictionary, then swap the new and old Dictionaries. Judging by the crash stack, something, somewhere is not correctly doing this and is instead modifying a List that is currently in-use. (Unfortunately there's no good way to validate that data structures are immutable in .NET.)
It would be really useful if someone could provide some example situations when this occurs which I might be able to test with since, like I said, I don't believe I've seen this happen even once. (Log files are useful here in case you have different settings than me, for example.)