Mallocator and 'shared'
bitwise via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Feb 10 15:57:18 PST 2017
https://github.com/dlang/phobos/blob/cd7846eb96ea7d2fa65ccb04b4ca5d5b0d1d4a63/std/experimental/allocator/mallocator.d#L63-L65
Looking at Mallocator, the use of 'shared' doesn't seem correct
to me.
The logic stated in the comment above is that 'malloc' is thread
safe, and therefore all methods of Mallocator can be qualified
with 'shared'.
I thought that qualifying a method as 'shared' meant that it
_can_ touch shared memory, and is therefore _not_ thread safe.
The following program produces this error:
"Error: shared method Mallocator.allocate is not callable using a
non-shared object"
import std.experimental.allocator.mallocator;
int main(string[] argv) {
Mallocator m;
m.allocate(64);
return 0;
}
And the above error is because it would be un(thread)safe to call
those methods from a non-shared context, due to the fact that
they may access shared memory.
Am I wrong here?
More information about the Digitalmars-d-learn
mailing list