Trying to sort shared data with a predicate causes 'unable to format shared objects'

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 17 10:18:36 PDT 2014


On 06/17/2014 08:51 AM, George Sapkin wrote:> Does making an array copy 
with shared cast away make any sense?
 >
 > auto n = 10;
 > auto sharedData = new shared SomeClass[n];
 > foreach (i; 0..n) sharedData[i] = new shared SomeClass(i);
 >
 > auto nonSharedData = cast(SomeClass[]) sharedData[0..$];
 > auto sorted = sort!((a, b) => a.value < b.value)(nonSharedData);
 >
 > This seems to work but what are the implications?

Shared data can be accessed by more than one thread. Unless it is 
locked, other threads may see the array in an inconsistent state.

Ali



More information about the Digitalmars-d-learn mailing list