An important pull request: accessing shared affix for immutable data

tsbockman via Digitalmars-d digitalmars-d at puremagic.com
Fri Feb 12 17:02:10 PST 2016


On Friday, 12 February 2016 at 19:12:48 UTC, Andrei Alexandrescu 
wrote:
> * If the buffer is const, then the allocator must 
> conservatively assume it might have been immutable and 
> subsequently shared among threads. Therefore, several threads 
> may request the affix of the same buffer simultaneously. So it 
> returns a reference to a shared affix.

What about providing a way to mark a piece of data as 
thread-local at allocation time?

The allocator could then stick it in a separate memory range from 
the (potentially) shared stuff, and just issue a fatal `Error` if 
an attempt was made to access it from the wrong thread.

This would prevent `const` from triggering unnecessary atomic ops 
or locks. The main disadvantage I see is that the logic to find 
the correct reference count address would be a little more 
complicated, but I suspect this would be a good trade-off given 
how expensive thread-safe memory operations can be.


More information about the Digitalmars-d mailing list