parallel processing - C# parallelism in LINQ -
i know if safe way of calculating x in code below.
public static ienumerable<object> parse(object obj, ref int x) { x += 10; return new list<object>(); } public static void query(list<object> obj) { int x = 0; var result = obj .asparallel() .select(o => parse(o, ref x)) .aggregate((a, b) => a.concat(b)); } this shortened version of code. want x kind of static counter parallel executions of parse. hope not confusing.
definitely not safe. need use interlocked class.
public static ienumerable<object> parse(object obj, ref int x) { interlocked.add(ref x, 10); return new list<object>(); }
Comments
Post a Comment