associative array with Parallel
frame
frame86 at live.com
Thu Jul 22 06:01:06 UTC 2021
On Thursday, 22 July 2021 at 05:53:01 UTC, jfondren wrote:
> On Thursday, 22 July 2021 at 05:46:25 UTC, seany wrote:
>> But what about this :
>>
>> int [ string ] ii;
>> ii.length = somearray.length;
>> foreach(i,dummy; parallel(somearray)) {
>> string j = generateUniqueString(i);
>> ii[j] ~= somefunc(dummy);
>> }
>>
>>
>> Is this also guaranteed thread safe?
>
> No. Consider
> https://programming.guide/hash-tables-open-vs-closed-addressing.html
>
> In the open-addressing case, one thread may be searching the
> backing array while another thread is modifying it. In the
> closed-addressing case, one thread may be modifying a linked
> list while another thread is searching it.
This is another parallel foreach body conversion question.
Isn't the compiler clever enough to put a synchronized block here?
More information about the Digitalmars-d-learn
mailing list