Memory allocation purity

via Digitalmars-d digitalmars-d at puremagic.com
Thu May 15 04:48:00 PDT 2014


On Thursday, 15 May 2014 at 11:03:35 UTC, Don wrote:
>> And you can still access globals, you just need a guarantee 
>> that globals don't change until you are done.
>
> Sure, but how can the compiler statically check that? It's a 
> tough problem.
> (That's not a rhetorical question, BTW. If you have a solution, 
> that would be awesome).

What you need is some way to formally specify what a lock covers 
or rather register what globals can be accessed in a transaction. 
So you basically need some sort of whole program analysis.

With transactional memory you only take the lock if the 
transaction fails, so it is ok if locking is slow or to take 
multiple locks. The CPU reverts to regular mutex based locking 
and clears the cache if another thread touch the memory that has 
been used in the transaction.

At least that is how I read the Haswell documentation.

> I agree, I'd personally like to have an annotation '@global', 
> and put 'pure:' at the top of every module.

It makes a lot of sense to put the annotation burden on the 
things you want less of, yes. "Do I really need to make this 
@global? Maybe I should do it some other way…"



More information about the Digitalmars-d mailing list