Passing large or complex data structures to threads
John Colvin
john.loughran.colvin at gmail.com
Sun May 26 06:07:38 PDT 2013
On Sunday, 26 May 2013 at 12:08:41 UTC, Joseph Rushton Wakeling
wrote:
> On 05/24/2013 05:59 PM, Ali Çehreli wrote:
>> The following simple example uses mutable data but it should
>> work with 'const' too.
>
> Limiting ourselves to read-only, won't there still be a
> slowdown caused by
> multiple threads trying to access the same data? The
> particular case I have
> will involve continuous reading from the data concerned.
Not necessarily. It really depends on the memory access patterns
of the algorithms, the number of threads, the size of the data,
the number/size/hierarchy of cpu caches, the number of CPUs.
Hard and fast rule: If your threads are reading data that is
distant (i.e. one thread reading from around the beginning of a
long array, the second reading from the end) then the fact that
they happen to be the same data "object" is irrelevant.
Also, remember that in the short term the CPUs are all keeping
their own independent copies of the relevant parts of the data in
caches anyway.
More information about the Digitalmars-d-learn
mailing list