3 ms·
Yes, but the point is, that in a functional language, hash-tables need not be thread-safe, as they are immutable. Only the variable binding has to be transactio
by tomp 14y ago
Yes, but the point is, that in a functional language, hash-tables need not be thread-safe, as they are immutable. Only the variable binding has to be transactional.
In a functional language, the code would be:
transaction {
local a = !x
local b = copy a with b[i] = a[i] + 1
x := b
}
where `!x` is referencing a transactional variable and `:=` is setting it.
- masklinn 14y ago> Yes, but the point is, that in a functional language, hash-tables need not be thread-safe As I and you noted, that's irrelevant, making the collection "thread-safe" (in the usual acception of the term, namely that concurrent accesses to the collection will not put the collection in an incorrect state) would not fix the situation since the increment is done outside the collection. > Only the variable binding has to be transactional. My point being precisely that the binding still has to be transactional: pure values are not sufficient to save you. > In a functional language, the code would be: Erm... I know. And that's not "in a functional language" that's in haskell, other languages will use different solutions.