hawkw / sharded-slab

a lock-free concurrent slab (experimental)
MIT License
269 stars 17 forks source link

Why does TID require one extra bit? #74

Open loyd opened 2 years ago

loyd commented 2 years ago

In tid.rs LEN is defined as: https://github.com/hawkw/sharded-slab/blob/8ebe120fd28b3a463932bbf0728e2baf5a558840/src/tid.rs#L47

that gives for the default config (MAX_THREADS = 4096) 13 bit space instead of 12:

    assert_eq!(Tid::<crate::cfg::DefaultConfig>::LEN, 13);

Meanwhile, we have two different checks for TID overflow:

  1. https://github.com/hawkw/sharded-slab/blob/8ebe120fd28b3a463932bbf0728e2baf5a558840/src/tid.rs#L163
  2. https://github.com/hawkw/sharded-slab/blob/8ebe120fd28b3a463932bbf0728e2baf5a558840/src/shard.rs#L296

I've missed something?

loyd commented 2 years ago

Any thoughts? Maybe I missed something. Extra bit would be most welcome =)

hawkw commented 1 year ago

this might be a bug on my part, whoops!