M2 icon indicating copy to clipboard operation
M2 copied to clipboard

Hash counter should be atomic, not thread local

Open d-torrance opened this issue 1 year ago • 0 comments

Consider the following example:

i1 : Foo = taskResult schedule(() -> new Type of HashTable)

o1 = Foo

o1 : Type

i2 : youngest(Foo, Matrix)

o2 = Matrix

o2 : Type

That doesn't seem right! Any user-defined classes should definitely be younger than ones defined in Core so that garbage collection works as expected.

But indeed, Foo has a much smaller hash code:

i3 : hash Foo

o3 = 1050004

i4 : hash Matrix

o4 = 1150524

This is because the hash counter is thread local, and we only have a gap of 10,000 between the starting point for each thread:

https://github.com/Macaulay2/M2/blob/ec9e9ac60ed4a8e791448942202f077a88a87e15/M2/Macaulay2/d/expr.d#L27

Instead, I think we might consider using an atomic hash counter.

d-torrance avatar Jul 14 '24 12:07 d-torrance