Bug 8077 – Regression (2.058): .reserve does not work for shared arrays

Status
RESOLVED
Resolution
INVALID
Severity
regression
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-05-10T02:39:00Z
Last change time
2012-05-16T11:30:15Z
Assigned to
nobody
Creator
andrej.mitrovich

Comments

Comment #0 by andrej.mitrovich — 2012-05-10T02:39:07Z
This worked in 2.057: void main() { shared int[] a; a.reserve(1024); } Now: D:\DMD\dmd2\windows\bin\..\..\src\druntime\import\object.di(597): Error: template object.reserve(T) cannot deduce template function from argument types !()(shared(int[]),int)
Comment #1 by bugzilla — 2012-05-16T11:06:45Z
I'm going to argue that although the code compiled in 2.057, it was not correct and had latent concurrency bugs. The problems are: 1. being shared doesn't mean that assignments to an array are atomic 2. there is no obvious place to put a lock around updating a shared resource like a shared array 3. locks can be very, very slow. Shared does not mean "automatically insert locks" Therefore, I'm going to mark this as invalid. In essence, you (the programmer) has to decide how to manage the memory is to be controlled by a shared array. You can allocate an array as thread local, then cast it to shared as a last step (probably the best approach). If the array is already shared, you'll have to protect the resize with a lock that fits in with your data structure.
Comment #2 by andrej.mitrovich — 2012-05-16T11:30:15Z
Well I thought shared was going to become some sort of gateway to safe-by-default concurrent programming, I guessed wrong. This section needs to be updated (by someone who knows exactly what shared does): http://dlang.org/attribute.html#shared Some partial information is here: http://dlang.org/migrate-to-shared.html#shared