Skip to content

Instantly share code, notes, and snippets.

@ashic
Created December 20, 2015 20:24
Show Gist options
  • Select an option

  • Save ashic/28d5f1d5ab1e3f0af716 to your computer and use it in GitHub Desktop.

Select an option

Save ashic/28d5f1d5ab1e3f0af716 to your computer and use it in GitHub Desktop.
1. Large array (yes, allocate. unmanaged mem can work even better, but ok with managed).
2. Have a "marker" for each writer and each reader.
3. Treat array as a circular buffer. Writers write messages and progress write marker. Up to the point where array size isn't filled.
4. Readers read till there are messages.
5. Have a reader for each handler. Each handler reads all written messages, but processes those that match criterion (type code, clr type, whatever).
6. Array entries can be cache aligned (i.e. struct with layout padding to 64B).
Easiest to get running is single producer, multi consumer. Should get 100s of millions per sec on moderately powerfull hardware.
1PMC can be done pretty much lock free. For multi producers, there are ways to make it lock free (i.e. allocate sections of stretches for
each writer to deal with contention).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment