Comment

Comment by ridiculous_fish

A fascinating design decision of Hashtable in .NET is its support for multiple readers AND a single writer.

In C++ or Rust, we get multiple readers OR a single writer. Shared ref or exclusive mut, pick one. But in .NET we have AND not OR: one writer AND multiple readers, all concurrent.

This works because .NET's GC can tolerate the race. A writer may trigger a table rehash, and a reader will read either the old or new table. If the reader loads the old table, it won't be deallocated until it's done: the GC will keep it alive.

Any cool uses of this one writer AND multiple readers?

https://learn.microsoft.com/en-us/dotnet/api/system.collecti...

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton